vbscript - VBS: Permission denied when deleting a file or a folder -


this code, first checks folder contains installer, if found, runs uninstall , deletes uninstall.exe if still exists. lastly, deletes folder itself.

dim objfso set objfso = createobject("scripting.filesystemobject") set wshshell = wscript.createobject("wscript.shell") if objfso.folderexists("c:\installer_3_00_00")      set objfolder = objfso.getfolder("c:\installer_3_00_00")     if objfso.fileexists("c:\installer_3_00_00\uninstall.exe")         wshshell.run "c:\installer_3_00_00\uninstall.exe -q"     end if     if objfso.fileexists("c:\installer_3_00_00\uninstall.exe")         set objfile=objfso.getfile("c:\installer_3_00_00\uninstall.exe")         objfile.delete true     end if objfolder.delete true else end if  set objfso = nothing 

the problem is: says permission denied trying delete file or folder. cross checked deleting manually , worked. have searched similar problems in forum none of helped me solve particular issue.

any suggestions appreciated. thanks

p.s tried formatting code here, still not able format correctly.

your problem caused (un)installer still running when try delete it, because call:

wshshell.run "c:\installer_3_00_00\uninstall.exe -q" 

returns without waiting program finish. change line this:

wshshell.run "c:\installer_3_00_00\uninstall.exe -q", 0, true 

Comments