• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 776
  • Last Modified:

How to copy files with a batch (dos) file to a folder with files witch is locked.

I have a server (2003 standard ed) on witch I will copy files with a batch (dos) file to a folder with files witch is locked. The files is locked becouse some userers always forget to turn down programs witch uses the files.
0
jontebgood
Asked:
jontebgood
  • 10
  • 4
  • 3
  • +4
1 Solution
 
Seelan NaidooMicrosoft Systems AdminCommented:
look at a utility called Robocopy.exe (Robust File Copy Utility) part of the Windows 2003 Resource Kit

You can download it here:

http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
0
 
JimsZCommented:
you can use switches in robocopy to skip the open files and will re-try the next time the batch file is ran
0
 
truluCommented:
On your server go to computer Administrative Tools - Computer Management and than open the node Shared Folders. Click on the open files map and delete any connections there. Here you can see witch pc's are still connected to some files on the server. If you remove the open connections, it can solve your problem.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jontebgoodAuthor Commented:
Thanks. but i must do it automaticly with a bat file or vbs file
0
 
Seelan NaidooMicrosoft Systems AdminCommented:
you can run it automatically as a schduled task.

Eg: create bat file..

command line for bat file

robocopy.exe [source] [destination] /SEC /MIR /LOG+:[location]

So, then file will be called copy.bat, and contains the above data.

You then create a Scheduled Task, supply credentials to run the .bat file..
Thats it..

If you need help, list details of what needs to be done, and we will help you get the result you require.
0
 
jontebgoodAuthor Commented:
I missed the comment about robocopy. Now i have tried that one but still i cant use it to copy to dest folder withhas files witch ius locked.

i use following command:

robocopy D:\Senaste_version\ D:\test\ *.* /MIR /ZB /SEC /LOG:d:\Test.txt
0
 
jontebgoodAuthor Commented:
------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP010
-------------------------------------------------------------------------------

  Started : Mon May 09 16:08:12 2005

   Source : D:\Senaste_version\
     Dest : D:\test\

    Files : *.*
          
  Options : *.* /S /E /COPY:DATS /PURGE /MIR /ZB /R:1000000 /W:30

------------------------------------------------------------------------------

                       104      D:\Senaste_version\
          Newer                    4.0 m      AGDAPS.exe
2005/05/09 16:08:12 ERROR 32 (0x00000020) Copying File D:\Senaste_version\AGDAPS.exe
The process cannot access the file because it is being used by another process.

Waiting 30 seconds... Retrying...
0
 
LittleRed1Commented:
It looks like you're going to have to find a way of forcing the file closed. I know that some backup programs have the ability to read locked files but it's not something I've come across from the command line. In the past what I've done is use the /r and /w switches in robocopy to skip the files, but re-run robocopy in a loop until all the required files have been copied. This unfortunately means waiting for people to close the application or log off, which may not suit you.

Is this on a Citrix (or Terminal Server), workstation or a file on a network share?
0
 
jontebgoodAuthor Commented:
its on a fileserver. the users have gone home when this copy is made (its updates the files so they always run the lastes versions of the files) if they dont log out no copy will be done and we cant run on lates version. and its very imprtant to do this.
0
 
Michael PfisterCommented:
Use rmtshare.exe (Windows Resource Kit) do remove the share right before the copy process (and kick off all users) and the same tool to recreate the share afterwards.

Hope it helps,

Michael
0
 
jontebgoodAuthor Commented:
sounds smart!! i will test brb
0
 
Seelan NaidooMicrosoft Systems AdminCommented:
do you need to copy the AGDAPS.exe, because you can exclude it with robocopy, and copy everything else

robocopy D:\Senaste_version\ D:\test\ *.* /MIR /ZB /SEC /LOG:d:\Test.txt /XF AGDAPS.exe
or
robocopy D:\Senaste_version\ D:\test\ *.* /MIR /ZB /SEC /LOG:d:\Test.txt /XF "AGDAPS.exe"


0
 
jontebgoodAuthor Commented:
agdaps.exe IS the file i want to update + 10 other files (dlls).
0
 
Seelan NaidooMicrosoft Systems AdminCommented:
have a look at the following, you might be able to combine with robocopy

http://searchwinsystems.techtarget.com/tip/0,289483,sid68_gci1086179,00.html?track=NL-120&ad=513788

download tool

http://ccollomb.free.fr/unlocker/
0
 
jontebgoodAuthor Commented:
problem solved. we will make a so called bootstrapper witch will solve the problem. thank you very much guys. i dont know how to do can i give points to someone even if we didnt reach the end of this problem i really appritiate your help.
0
 
LongbowCommented:
rem Stores all opened files in a .txt file with their ID
rem You can use a 2nd "| find" after the 1st ont to be more selective.
net file|find /I "\">c:\netfile.txt
rem Dislays the opened ID's files
FOR /F "tokens=1 delims= " %a in (c:\netfile.txt) do @echo %a
rem Same as above but closed all files ID in c:\netfile.txt
FOR /F "tokens=1 delims= " %a in (c:\netfile.txt) do @net file %a /CLOSE
rem Here yoy can delete the txt file but the next time you run
rem  this command it will be overwritten.

Sorry i can't test anymore because my users are working on the network at this time.
0
 
jontebgoodAuthor Commented:
strange the txt file is empty when i do this :(
0
 
LongbowCommented:
The net file command must be executed on the server from where the files are opened only.
0
 
jontebgoodAuthor Commented:
yes i thought so i  tried no result in txt file sorry ..
0
 
LongbowCommented:
You can force logoff users in the Active Directory :
In your Policy / "Computer Configuration / Windows Settings / Security Settings / Local Policies / Security Options / Microsoft Network Server: Disconnect clients when logon hours expire"
0
 
jontebgoodAuthor Commented:
ah great that is the solotion ty u guys for all help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 4
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now