Jump to content
Sign in to follow this  

self deleting script

Recommended Posts

My link

Func _SelfDelete($iDelay = 0)
    Local $sCmdFile
    FileDelete(@TempDir & "\scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & ' > nul' & @CRLF _
             & ':loop' & @CRLF _
             & 'del "' & @ScriptFullPath & '"' & @CRLF _
             & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
             & 'del %0'
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)

I tryed to make a script self delete itself but when the function is called it has a line error here :

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

I did not edit it but could I just be applying this function badly?

If you were twice as smart, you'd still be stupid.

Share this post

Link to post
Share on other sites

I'm pretty fluent in batch and I think you could make your batch file a bit more stable. It could solve your problem (not sure if it will, but worth a shot). So here is the batch file I would use for something like this

timeout /t [TIME IN SECONDS]
if exist [FILE NAME] del [FILE NAME] && del %0
goto Loop

I would use timeout instead of ping. It's easier to use and generally more stable

The 1st line of the Loop routine is much more stable than what you have. Using a double & will make it so that the 2nd part only happens if the first part happens. If it cannot find your file (or if it cannot delete it) then it will not del %0 and it will move on to the next line (keep looping).

Give that batch a try and see if it works for you!


Share this post

Link to post
Share on other sites

Hi BubbleGum Danser

Test this !

Run(@ComSpec & ' /c del ' & @ScriptName, @ScriptDir, @SW_HIDE) ; End of the script

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...