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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.