I want some help with a script that copys and replacec a file i an location, and if the file is locked becourse its beeing used, a prompt will appear telling the user to close the program, and when the user closes the program and presses ok, the script will copy and replace the file.

Thank you
0 Comments   [ - ] Hide Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity



You can try to use this.

ON error resume next
Function DeleteFIle ()
ON error resume next
file1 = "c:\temp\1.msi"
file2 = "c:\temp\2.msi" 'destination filee
Set fso = CreateObject("Scripting.FileSystemObject")
Set plik = fso.GetFile(file1)

plik.Copy file2 'copy file to destination folder
If Err.Number <> 0 Then
WScript.Echo "Please close program"
wscript.sleep 5000 'time in ms
result = DeleteFIle()
WScript.Echo "File was repleced"
end if
End function

result = DeleteFIle()
msgbox "THX"
Answered 02/20/2012 by: Bula
Yellow Belt

Please log in to comment
Thanks Bula

It worked like a charm :)
Answered 02/21/2012 by: spajder
Yellow Belt

Please log in to comment
I think this will only prompt when file2 is an executable. Otherwise, it will just overwrite file2 even though it is open.

If it's just program files that you need to check are open, you could use the Win32_Process class in WMI and even terminate the process if it is in use.
Answered 02/22/2012 by: andys0123
Orange Senior Belt

Please log in to comment