Close Open Files Scheduled Task

Hello

I have a Windows 2003 file server which holds home directories etc. I am wanting to copy certain directories across to another server using Robocopy using the /MIR command (Mirror). Only problem I am having is that the task will stop if a file is open/locked.

After looking on the web, I cannot see a command that will ignore open/locked files when using Robocopy. Is there a script I can run to kill ALL open/locked files on the server? At least then I know the copy will work.

Thanks.
mishcondereyaAsked:
Who is Participating?
 
ren20atomCommented:
Yes please run it in a command prompt window and check if you get the desired results.
You can cross check this by going to My Computer => Right Click => Manage => Shared Folders=> Open Files=> And check if all the open files are closed
0
 
ren20atomCommented:
Hi,

Please test if this works for you:

Command to Close All Open Files
for /f "skip=4 tokens=1" %a in ('net files') do net files %a /close
The command works by passing the file ID elements from the list produced by the net files command to the action argument of the for command, net files file ID /close. When you use the iterative substitution (%a in this case) as part of a batch file, the substitution needs to be %%a. For the batch file version of the command, use the following syntax:
for /f "skip=4 tokens=1" %%a in ('net files') do net files %%a /close
In both cases, this command will appear to return an error because the last line of output from net files is "The Command Completed Successfully" and there is no file ID denoted as "The".

Note: The Server Service must be running in order for this command to work.
Note: This command closes all open shared files and removes the file locks of these files; It in no way attempts to understand the nature of the files or the client programs that have the files open. In some cases data loss may occur if users have not saved the files prior to the use of this command. It is recommended that you test this command in your enviroment prior to its application in a production capacity.
0
 
mishcondereyaAuthor Commented:
Sorry, I'm a bit of a noob.

Do I run the above in a command prompt window?

Example - for /f "skip=4 tokens=1" %a in ('net files') do net files %a /close
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
mishcondereyaAuthor Commented:
Ok, cool.

Will the above command work in VBS?
0
 
mishcondereyaAuthor Commented:
Thanks.
0
 
ren20atomCommented:
Hi,
The above command might not work exactly in VBS as this is in the command prompt format, but you could get a VBS File to run a command and that could be the above command.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.