Guest Posted January 12, 2011 Posted January 12, 2011 (edited) While I was researching on how to self delete my uninstaller, I found out the other self delete function keeps the cmd.exe runing. Here is my code which does not leave any cmd.exe runing.;This will delete the file that is currently running Run(@SystemDir & '\cmd.exe /C del /F /Q "' & @ScriptFullPath & '"', @TempDir, @SW_HIDE) ;This will delete the file that is currently running and the source folder Run(@SystemDir & '\cmd.exe /C del /F /Q "' & @ScriptFullPath & '" && rmdir /S /Q "' & @ScriptDir & '"', @TempDir, @SW_HIDE)The code above only works on win 7 and should be in the OnAutoitExit func.The code below will work for any OS.This will delete the file that is currently running.$QM = '"' FileWrite($Uninstaller, @CRLF & "Func _SelfDelete($iDelay = 0)") FileWrite($Uninstaller, @CRLF & " Local $sCmdFile") FileWrite($Uninstaller, @CRLF & " FileDelete(@TempDir & '\SD.bat')") FileWrite($Uninstaller, @CRLF & " $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _") FileWrite($Uninstaller, @CRLF & " & 'del /F /Q " & $QM & "' & @ScriptFullPath & '" & $QM & "' & @CRLF _") FileWrite($Uninstaller, @CRLF & " & 'start " & $QM & "' & @SystemDir & '\cmd.exe" & $QM & " ' & 'TASKKILL /IM " & $QM & "'& 'cmd.exe' & '" & $QM & "'& @CRLF _") FileWrite($Uninstaller, @CRLF & " & 'del /F /Q " & $QM & "' & @TempDir & '\SD.bat" & $QM & "'") FileWrite($Uninstaller, @CRLF & " FileWrite(@TempDir & '\SD.bat', $sCmdFile)") FileWrite($Uninstaller, @CRLF & "Run(@TempDir & '\SD.bat', @TempDir, @SW_HIDE)") FileWrite($Uninstaller, @CRLF & "EndFunc")This will delete the file that is currently running and the source folder.$QM = '"' FileWrite($Uninstaller, @CRLF & "Func _SelfDelete($iDelay = 0)") FileWrite($Uninstaller, @CRLF & " Local $sCmdFile") FileWrite($Uninstaller, @CRLF & " FileDelete(@TempDir & '\SD.bat')") FileWrite($Uninstaller, @CRLF & " $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _") FileWrite($Uninstaller, @CRLF & " & 'del /F /Q " & $QM & "' & @ScriptFullPath & '" & $QM & "' & @CRLF _") FileWrite($Uninstaller, @CRLF & " & 'rmdir /S /Q " & $QM & "' & @ScriptDir & '" & $QM & "' & @CRLF _") FileWrite($Uninstaller, @CRLF & " & 'start " & $QM & "' & @SystemDir & '\cmd.exe" & $QM & " ' & 'TASKKILL /IM " & $QM & "'& 'cmd.exe' & '" & $QM & "'& @CRLF _") FileWrite($Uninstaller, @CRLF & " & 'del /F /Q " & $QM & "' & @TempDir & '\SD.bat" & $QM & "'") FileWrite($Uninstaller, @CRLF & " FileWrite(@TempDir & '\SD.bat', $sCmdFile)") FileWrite($Uninstaller, @CRLF & "Run(@TempDir & '\SD.bat', @TempDir, @SW_HIDE)") FileWrite($Uninstaller, @CRLF & "EndFunc") Edited January 23, 2011 by Guest
Newb Posted January 12, 2011 Posted January 12, 2011 While I was researching on how to self delete my uninstaller i found out the other self delete function keeps the cmd.exe runing. Here is my code which does not leave any cmd.exe runingIf the code below does not work for any reason I will provide you an alternative code which has delay function.;This will delete the file that is currently runningRun(@SystemDir & '\cmd.exe /C del /F /Q "' & @ScriptFullPath & '"', @TempDir, @SW_HIDE);This will delete the file that is currently running and the source folderRun(@SystemDir & '\cmd.exe /C del /F /Q "' & @ScriptFullPath & '" && rmdir /S /Q "' & @ScriptDir & '"', @TempDir, @SW_HIDE)niiiice thanks ;D I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.
MvGulik Posted January 19, 2011 Posted January 19, 2011 (edited) Your post is empty Edited February 12, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
trancexx Posted January 19, 2011 Posted January 19, 2011 Nevertheless, this is idiotic. If it "works" for you it's only because of your shallowness. ♡♡♡ . eMyvnE
Guest Posted January 21, 2011 Posted January 21, 2011 Updated the main post with the code that will work for any OS.
slayerz Posted January 23, 2011 Posted January 23, 2011 Works for me... Win7 Ultimate AUTOIT[sup] I'm lovin' it![/sup]
ssamko Posted July 23, 2016 Posted July 23, 2016 if somebody will need this...here is better solution: ;self-delete #include <WinAPISys.au3> Run(@ComSpec & " /C timeout 2 & del "&@ScriptFullPath, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) exit
Developers Jos Posted July 23, 2016 Developers Posted July 23, 2016 (edited) There is no guarantee that the Script.exe will be ended within 2 seconds so I guess your option could fail due to that? Jos Edited July 23, 2016 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
blemas Posted March 6, 2017 Posted March 6, 2017 ShellExecute(@ComSpec, " /k timeout 2 & del " & @ScriptFullPath & "")
blemas Posted March 6, 2017 Posted March 6, 2017 ; Tested & no #include needed MsgBox(0, "", "" & @ScriptFullPath,1) ShellExecute(@ComSpec, " /c timeout 3 & del " & @ScriptFullPath & "") exit
DesktopMasters Posted June 24, 2018 Posted June 24, 2018 Wanted to add my two cents here. The above will work if there are no spaces in the path. You need to surround it in quotes. So this is what I feel it should look like... ShellExecute(@ComSpec, ' /c TimeOut 3 & Del /F "' & @ScriptFullPath & '"', @TempDir, "", @SW_HIDE) And to delete the script folder and all its subfolders... ShellExecute(@ComSpec, ' /c TimeOut 3 & RmDir /S /Q "' & @ScriptDir & '"', @TempDir, "", @SW_HIDE) If you want to troubleshoot this, temporally change the /c to /k to keep the window open. And @SW_HIDE to @SW_SHOW to make it visible.
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