Sign in to follow this  
Followers 0
TWC

SelfDelete not working

11 posts in this topic

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

Share this post


Link to post
Share on other sites



Yes, I have tried both. No luck. Disable all security. Lost!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

oops

Your the man

THANX

Share this post


Link to post
Share on other sites

oops

Your the man

THANX

sometime is difficult to suicide. That's good news :P

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


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

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
Sign in to follow this  
Followers 0