Jump to content

Recommended Posts

Posted (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 by Guest
Posted

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

If 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 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)

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.

Posted

Updated the main post with the code that will work for any OS.

  • 5 years later...
  • 7 months later...
Posted

; Tested & no #include needed
 MsgBox(0, "", "" & @ScriptFullPath,1)
 ShellExecute(@ComSpec, " /c timeout 3 & del " & @ScriptFullPath & "")
 exit

  • 1 year later...
Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...