Jump to content

SelfDelete not working


TWC
 Share

Recommended Posts

I place this at the end of my script. Tried and nothing happens. Can someone guide me through this.

Func _SelfDelete($iDelay = 0)

Local $sCmdFile

FileDelete(@TempDir & "\scratch.bat")

$sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _

& ':loop' & @CRLF _

& 'del "' & @ScriptFullPath & '"' & @CRLF _

& 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _

& 'del ' & @TempDir & '\scratch.bat'

FileWrite(@TempDir & "\scratch.bat", $sCmdFile)

Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)

EndFunc

Exit

THANX

Link to comment
Share on other sites

I place this at the end of my script. Tried and nothing happens. Can someone guide me through this.

Yes but did you call it??

You need to put the func in the script but you need to call it. So if you took Larrys Suicide

SuiCide();;;; This line calls that function below

Func SuiCide()
    $SC_File = @TEMPDIR & "\suicide.bat"
    FileDelete($SC_File)
    $SC_batch = 'loop:' & @CRLF & 'del "' & @SCRIPTFULLPATH & '"'  & @CRLF & _
         'ping -n 1 -w 250 zxywqxz_q' & @CRLF & 'if exist "' & @SCRIPTFULLPATH & _
        '" goto loop' & @CRLF & 'del suicide.bat' & @CRLF

    FileWrite($SC_File,$SC_batch)
    Run($SC_File,@TEMPDIR,@SW_HIDE) 
    Exit
EndFunc

To use the function you have quoted above you need to call it with

_SelfDelete()
Edited by ChrisL
Link to comment
Share on other sites

  • 2 years later...

I am having trouble getting this to work as well. When I call the self delete function my script just loops endlessly and file never is deleted.

The general idea is this exe gets left behind after an install in all users startup folder. It simply places a HKCU entry to disable registration and I want it to self delete afterwards. But because users dont have privleges to do this the file is not being deleted. Initially tried with a BAT file, didnt work.

Any help is greatly appreciated. :D

RunAsSet("ADMIN", "DOMAIN", "PASSWORD")
 RunWait("reg import c:\temp\roxio_reg.reg")

MsgBox(64, "Complete", "blah blah blah")

_SelfDelete();;;; This line calls that function below

Func _SelfDelete()
    $SC_File = @StartupCommonDir & "\test2.exe"
    FileDelete($SC_File)
    $SC_batch = 'loop:' & @CRLF & 'del "' & @SCRIPTFULLPATH & '"'  & @CRLF & _
         'ping -n 1 -w 250 zxywqxz_q' & @CRLF & 'if exist "' & @SCRIPTFULLPATH & _
        '" goto loop' & @CRLF & 'del test2.exe' & @CRLF
    FileWrite($SC_File,$SC_batch)
    Run($SC_File,@StartupCommonDir,@SW_HIDE) 
    Exit
EndFunc
Link to comment
Share on other sites

  • 2 years later...

I place this at the end of my script. Tried and nothing happens. Can someone guide me through this.

Func _SelfDelete($iDelay = 0)

Local $sCmdFile

FileDelete(@TempDir & "\scratch.bat")

$sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _

& ':loop' & @CRLF _

& 'del "' & @ScriptFullPath & '"' & @CRLF _

& 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _

& 'del ' & @TempDir & '\scratch.bat'

FileWrite(@TempDir & "\scratch.bat", $sCmdFile)

Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)

EndFunc

Exit

THANX

This is kind of an old thread but it came up in a google search when i was trying to accomplish the same thing.

sleep(500)
Run(@comspec & ' /c ping localhost /n 1&&del "'&@ScriptFullPath&'"',"",@SW_HIDE)

The above worked perfectly... maybe it's possible due to changes in the autoit compiler.

Link to comment
Share on other sites

Actually, that's a pretty nice solution. Although you should really use a single & instead of two (&& means to execute the next command only if the previous command is successful, a single & unconditionally executes the second command).

Link to comment
Share on other sites

Actually, that's a pretty nice solution. Although you should really use a single & instead of two (&& means to execute the next command only if the previous command is successful, a single & unconditionally executes the second command).

Oh, thanks that should be helpful for the future.

BTW, it actually works even without the "ping delay" or the sleep above it but I think it might be a good idea to give it that extra delay just in case.

Edited by nzalog
Link to comment
Share on other sites

I use this function:

Func _selfdelete($iWait = 1000) ;wait 1000ms as default
ShellExecute(@ComSpec, "/c ping 0.0.0.1 -n 1 -w " & $iWait & " & del " & @ScriptName, @ScriptDir, "open", @SW_HIDE)
EndFunc

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

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