Batch script to delete files/folder even open by user in share - batch-file

Can somebody guide me to delete folder/files in remote machine even when it's open by other user in share with write access.
I am getting error as
\remote\Destination\NEWFOL~2 - The process cannot access the file because it is being used by another process.
I am using psfile command from sysinternals but the session is again created before deletion.. I can see the session is closed.. immediately after close another session is created

Related

Ms Access 2010 FE application run via bat file BUT lock file *.laccdb remains open

First off I seached for this topic on previous questions and on the web but cannot find any that is giving or suggesting me the solution.
I'm NOT new to access and this really drives me crazy.
I have an Access 2010 frontend accdb file that is used as below:
The FE Analyzer.accdb is located in the Company Server#1 in a shared folder
On the Company Server#2 a .bat file was created that is scheduled to run every night, and the .bat lauches the Access FE file with Access Runtime (no full MS access on the server) with the usual command:
C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" "\\192.168.1.5\SharedFolder\Analyzer.accdb
"C:" drive above is the one of CompanyServer#2, the IP address 192.168.1.5 is the Server#1.
When the access file is run, a startup form opens, in the Load event of the form, a subroutine is called that does a bunch of calculations and writes into sql server. After calling the main subroutine, Access application is closed, like this:
Private Sub Form_Load()
Call Init
Application.Quit
End Sub
The schedule works perfectly every night, the Access file accdb does what it's expected to, no MSACCESS.EXE remains in the task manager - ok so far, BUT the *.laccdb lock file remains in the shared folder!
When, from my client PC I access the shared folder, I can manually delete the lock file without any problems.
As a work-around, in the .BAT file I had written a first line that removes the lock file before running the .accdb file again.
BUT now that's annoying again, because I set auto-compact on close, and it doesn't work, I think because the Access accdb file is not closed properly - the lock file still there being some evidence.
If I run the Access frontend file that is in the shared folder (just double click it and let the startup form run the main subroutine) from my client PC it works and no lock file remains.
If I run the .BAT file that is on the Server#2 from my client PC, also everything runs and no lock file remains.
Any clue?

How to check in MS SQL whether text or excel file is open or is being used by some user

I have a process where i will be reading data from files using bulk insert in MS SQL, this process runs in a job. But i am facing issue with this, some times the user keeps the files open during the job run and it fails.I want to implement a process where it checks for if the file is being currently used by some user before doing bulk insert, if yes then send out an mail alert saying 'xxx' user is using 'yyy' file name.Once the user closes the file then continue with the normal process rather than erroring out.

Running batch file on Remote Desktop login fails

As just extra protection, I am wanting to backup remote sql db to my location nightly. There is no VPN so...
I created a user on the 2008 db server for the sole purpose to log on from my office and download the db bak file nightly. Gave this user read permission on the backup directory (T:\Backup) and added to the remote users group.
I created a Automated task on my workstation that calls a rdp file that successfully connects to the db server as this user.
The rdp file specifies in the "Start a program" tab the following path:
C:\Windows\System32\mstsc.exe T:\Backup\copydb.bat
I have tested both parts:
1) Double-clicking the rdp file will login automatically. (WORKS)
2) I can then manualy open the dos prompt and run the bat file. (WORKS)
However, the bat file does not seem to execute on connection . There is no cmd window. I can douple-click on the bat file and the cmd window will flash and go away but does not execute. The only way I've been able to get it to execute is to open the prompt and then the file.
I thought that's what this would do:
C:\Windows\System32\mstsc.exe T:\Backup\copydb.bat
What am I missing?
This might be your problem.
Refer to this MS support article You cannot create a terminal server session to a Windows Server 2008-based computer by using an .rdp file that runs an initial program
To work around this problem, add the program path to the RemoteApp Programs list. To do this, follow these steps:
Click Start, click Run, type remoteprograms.msc, and then click OK.
In the actions pane, click Add RemoteApp Programs, and then click Next.
Click Browse, locate the program that you want to approve, click Next, and then click Finish.

How can I use a batch file to launch an application as a specific user?

I'm trying to figure out how I can use a batch file to launch Internet Explorer as a local user on the system hosting the batch file. Ideally I'd like to be able to double click the batch file and not have to enter user credentials. To break it down a bit:
User is logged onto the host system with a domain user (Server 2008 R2 Standard 64bit)
User can then double click on a batch file that will launch Internet Explorer as a local user on the host system, without prompting for the local user credentials
All I can find is information about NET USE, any help would be greatly appreciated!
"runas" command was intentionally designed to prompt for password. So, that is not your solution.
One of option is to create a scheduled task where you can store the password (safely) and run the scheduled task from batch file.
But if the batch file is distributable and not going to be run on same machine.. you may have to investigate on how to create a schedule task from batch file and then run it.
you may find this reference helpful

Error Running a Batch File To Copy A File

I am trying to run a batch file to copy a backup file from one location to other.
I keep on getting the error:
Invalid drive specification
My path is as follows:
\\server\drive:\folder\folder\folder\*.bak drive:\folder\.bak
That typically doesn't work out too well. You'll want this:
cp \\server\C$\folder\folder\folder\copy.bak C:\folder\copied.bak
This presupposes that you actually have access to the folder \\server\C$\folder\folder\folder from your box. If you do not, then you need to configure permissions correctly on the server to give you access.
You only have access to administrative shares (\\server\C$ <- the $ denotes an admin share) if you have administrative rights on the server. If you don't you need to actively share the folder in question, i.e. on the server, navigate to drive:\folder\folder\folder and share it (context menu of the folder, menu item Sharing and Security). Note that you need at least temporary admin rights on the server in order to create a share.
Do not forget to configure the permissions for the share you create, so that the limited account you are using for the copy process has read rights.
Once this is et up, you should be able to copy the files using
Copy \\Server\NewShareName\*.bak c:\folder\.bak
If you have problems with the files being in use by another process, have a look at robocopy instead of the copy command.

Resources