Aipion 4 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 Antop Share this post Link to post Share on other sites
Newb 5 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. Share this post Link to post Share on other sites
shai 0 Posted January 19, 2011 this code is not work for me. Share this post Link to post Share on other sites
MvGulik 86 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 ... Share this post Link to post Share on other sites
jvanegmond 306 Posted January 19, 2011 Check these too: github.com/jvanegmond Share this post Link to post Share on other sites
trancexx 1,013 Posted January 19, 2011 Nevertheless, this is idiotic. If it "works" for you it's only because of your shallowness. ♡♡♡ . eMyvnE Share this post Link to post Share on other sites
Aipion 4 Posted January 21, 2011 Updated the main post with the code that will work for any OS. Share this post Link to post Share on other sites
slayerz 0 Posted January 23, 2011 Works for me... Win7 Ultimate AUTOIT[sup] I'm lovin' it![/sup] Share this post Link to post Share on other sites
ssamko 0 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 Share this post Link to post Share on other sites
Jos 2,209 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. Share this post Link to post Share on other sites
blemas 0 Posted March 6, 2017 ShellExecute(@ComSpec, " /k timeout 2 & del " & @ScriptFullPath & "") Share this post Link to post Share on other sites
blemas 0 Posted March 6, 2017 ; Tested & no #include needed MsgBox(0, "", "" & @ScriptFullPath,1) ShellExecute(@ComSpec, " /c timeout 3 & del " & @ScriptFullPath & "") exit Share this post Link to post Share on other sites
DesktopMasters 0 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. Share this post Link to post Share on other sites