Aipion

Self Delete

12 posts in this topic

#1 ·  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 Antop

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

this code is not work for me.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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

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

Share this post


Link to post
Share on other sites

Works for me... Win7 Ultimate


AUTOIT[sup] I'm lovin' it![/sup]

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#11 ·  Posted

ShellExecute(@ComSpec, " /k timeout 2 & del " & @ScriptFullPath & "")

Share this post


Link to post
Share on other sites

#12 ·  Posted

; 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

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