Sign in to follow this  
Followers 0
kor

[solved] delete all EXE's, then delete self

6 posts in this topic

#1 ·  Posted (edited)

why isn't my code working?

_SelfDelete()

Sleep(2000)

For $i = 0 To 30
    If FileExists(@ScriptDir & "\*.exe") Then
        FileDelete(@ScriptDir & "\*.exe")
        Sleep(1000)
    Else
        ExitLoop
    EndIf
Next

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

I want the script to delete any and all EXE's from the directory the script is running in.

The reason I have self destruct first is because I dont want the script to get hung up trying to delete itself in the For Next loop.

Any ideas?

the current behavior is the script IS deleting itself, but not any other EXE's in the directory.

Edited by kor

Share this post


Link to post
Share on other sites



you can write sleep in cmd for wait tool to exit

Share this post


Link to post
Share on other sites

func delete($directory)
    $s = FileFindFirstFile($directory & "*.*")
    If $s = -1 Then Return
    while 1
        $filr = FileFindNextFile($s)
        If @error Then ExitLooop
        If @extended Then
            CloseExecMods($directory & "" & $file)
        else
            If StringRight($file, 3) == "exe" Then
               filedelete($directory & "" & $file)
            endIf
        endIf
    wEnd
EnddFunc

?


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

I've noticed that _SelfDestruct() doesn't actually delete the script until it exits.

Is there not a way to delete itself while the script still runs in memory?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I've noticed that _SelfDestruct() doesn't actually delete the script until it exits.

Is there not a way to delete itself while the script still runs in memory?

I think you can, but it requires a bit of a hack (or a big one) to delete the binary while it still runs in memory, you can't just have an app runing in the air, it has to be linked to something on the hard drive, even if its just an empty file. i forgot where I was reading about it

But you should just use the self delete function when you exit your script...

Edited by ApudAngelorum

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

This works nicely.

#NoTrayIcon
#include <File.au3>

$aFiles = _FileListToArray(@ScriptDir)

For $i = 1 To UBound($aFiles) - 1
    If StringInStr($aFiles[$i], "delete") Then
        ContinueLoop
    Else
        FileDelete(@ScriptDir & "" & $aFiles[$i])
    EndIf
Next

_SelfDelete()

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

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