/build/static/layout/Breadcrumb_cap_w.png

VBscript copy and replace file, prompt if locked

Hi

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   [ + ] Show comments

Answers (3)

Posted by: Bula 12 years ago
Yellow Belt
0
Hi,

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"
Err.Clear
wscript.sleep 5000 'time in ms
result = DeleteFIle()
else
WScript.Echo "File was repleced"
end if
End function

result = DeleteFIle()
msgbox "THX"
Posted by: spajder 12 years ago
Yellow Belt
0
Thanks Bula

It worked like a charm :)
Posted by: andys0123 12 years ago
Orange Senior Belt
0
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.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ