Sign in to follow this  
Followers 0
relheob

Delete script itself

5 posts in this topic

Hi,

I have a compiled script and want to delete this exe file itself after it has finsihed successfully.

How can I do this w/o rebooting or logging off?

Regards

Relheob

Share this post


Link to post
Share on other sites



Func _SelfDelete()
    Local $cmdfile
    FileDelete(@TempDir & "\scratch.cmd")
    $cmdfile = ':loop' & @CRLF _
            & 'del "' & @ScriptFullPath & '"' & @CRLF _
            & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
            & 'del ' & @TempDir & '\scratch.cmd'
    FileWrite(@TempDir & "\scratch.cmd", $cmdfile)
    Run(@TempDir & "\scratch.cmd", @TempDir, @SW_HIDE)
EndFunc


[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
Share on other sites

Or just simple:

Win9x, ME and NT:

Run("command.exe del """ & @ScriptFullPath & """", "", "@SW_HIDE")

Win2k and newer:

Run("command.exe /c del """ & @ScriptFullPath & """", "", "@SW_HIDE")

Share this post


Link to post
Share on other sites

Or just simple:

Win9x, ME and NT:

Run("command.exe del """ & @ScriptFullPath & """", "", "@SW_HIDE")

Win2k and newer:

Run("command.exe /c del """ & @ScriptFullPath & """", "", "@SW_HIDE")

<{POST_SNAPBACK}>

nah.. won't work because the script cannot delete itself when its still running....

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

Share this post


Link to post
Share on other sites

Func _SelfDelete()
    Local $cmdfile
    FileDelete(@TempDir & "\scratch.cmd")
    $cmdfile = ':loop' & @CRLF _
            & 'del "' & @ScriptFullPath & '"' & @CRLF _
            & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
            & 'del ' & @TempDir & '\scratch.cmd'
    FileWrite(@TempDir & "\scratch.cmd", $cmdfile)
    Run(@TempDir & "\scratch.cmd", @TempDir, @SW_HIDE)
EndFunc

<{POST_SNAPBACK}>

Many thanks. :)

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