Jump to content

Self Delete


Guest
 Share

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Your post is empty Edited 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 ...
 

Link to comment
Share on other sites

  • 5 years later...
  • Developers

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 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.
  :)

Link to comment
Share on other sites

  • 7 months later...
  • 1 year later...

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.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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