PhilipG Posted January 29, 2010 Share Posted January 29, 2010 I'm trying to accomplish a Uninstal script to delete all registry entries and files needed for an other script i've already written. Deleting the registry entries was no problem. But the simple task of deleting a folder seams to be a nightmare... I seriously need some help. I do understand why it doesn't work. The uninstal file is in the directory i wish to delete. I've tried to install a small script in the temp folder designed only to sleep(1000) (to give the unistalation wizard time to close so it could be deleteed) then delete the programs folder. But it failed. I've also tried doing the same but with a batch file instead of a script. The batch script gave me an error witch only proved my thesis. There's some kind of process using the programs folder so it can't be deleted. But al programs are closed, so my ideas are all out. Both script's managed to delete all files within the directory, but not the directory itself. Is there anyway of force delete folders and all content. Or is there a better way to tackle this problem? Help would really be appreciated Link to comment Share on other sites More sharing options...
James Posted January 29, 2010 Share Posted January 29, 2010 $hFile = FileOpen(@TempDir & "\~deltmp.bat", 2) $sCMDLine = _StringANSI2OEM(':CheckFile' & @CRLF & _ 'If exist "' & @ScriptFullPath & '" GOTO :DelFile' & @CRLF & _ 'Goto :CheckFile' & @CRLF & _ ':DelFile' & @CRLF & _ 'del /f /q "' & @ScriptFullPath & '"' & @CRLF & _ 'del /f /q "' & @TempDir & '\~deltmp.bat"') FileWrite($hFile, $sCMDLine) FileClose($hFile) Run(@TempDir & "\~deltmp.bat", @TempDir, @SW_HIDE) Exit Func _StringANSI2OEM($strText) Local $buf = DllStructCreate("char[" & StringLen($strText) + 1 & "]") Local $ret = DllCall("user32.dll", "int", "CharToOem", "str", $strText, "ptr", DllStructGetPtr($buf)) If Not (IsArray($ret)) Then Return SetError(1, 0, '') If $ret[0] = 0 Then Return SetError(2, $ret[0], '') Return DllStructGetData($buf, 1) EndFunc ;==>_StringANSI2OEM Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
PhilipG Posted January 29, 2010 Author Share Posted January 29, 2010 (edited) That pretty much did what i've already accomplished myself. it only delete the uninstall file. and if I change @scriptFullPath to @ScripDir it removes all files, but not the actual @ScriptDir. I want the whole folder to be removed! But thanks for trying! Edited January 29, 2010 by PhilipG Link to comment Share on other sites More sharing options...
GEOSoft Posted January 29, 2010 Share Posted January 29, 2010 Windows will not delete a folder if any file in that folder is in use. In your case you are using @ScriptDir which is assumably the same folder that you want deleted. Not going to happen becuase the script is still running so the folder can not be deleted with the script. Are you using a proper installer to install after the folder is deleted? If so which one? There are often provisions to do what you want right in the installer. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
PhilipG Posted January 29, 2010 Author Share Posted January 29, 2010 No i'm using a home made script. But how is it possible for files to run when they are deleted? The script deletes ALL files in @scriptdir including @scriptname Thats done with the batch file in the temp folder. The batch file starts with a seconds sleep to give @scriptname time to exit. So there are no programs running when the delete command is initiated! Or at least not that I know about! Link to comment Share on other sites More sharing options...
Fire Posted January 29, 2010 Share Posted January 29, 2010 I think you can use : Run("cmd.exe /c rmdir /Q /S " & "somefolder",@ScriptDir,@SW_HIDE) But all apps in that folder named in example somefolder would be killed before rmdir /Q /S . [size="5"] [/size] Link to comment Share on other sites More sharing options...
GEOSoft Posted January 29, 2010 Share Posted January 29, 2010 (edited) No i'm using a home made script. But how is it possible for files to run when they are deleted?The script deletes ALL files in @scriptdir including @scriptname Thats done with the batch file in the temp folder. The batch file starts with a seconds sleep to give @scriptname time to exit.So there are no programs running when the delete command is initiated! Or at least not that I know about!Then you may want to revisit your batch file and perhaps even adjust the sleep delay. Personaly I would probably want to run the script from someplace else, let the script delete the folder and then a simple batch file to delete the script. You might also want to check Task manager and make sure there are no processes running that involve that folder.I assume you are using RD /s /q as the command in your batch file.Edit: And I didn't mean that the function to delete the folder would be in the Uninstall. I meant in the new Install. Most proper installers have the ability to perform functions prior to the actual install taking place so you can do cleanup at that point. Edited January 29, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now