Jump to content

Delete the file after running it?


Recommended Posts

Hi,

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  ;==>_SelfDelete

so long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

No, prob. I think MHz wrote it. :D

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

This calls autoits built in functions.. no second script.

you have to exit the script before you can delete it with filedelete, the other way that th.meger is good too.

Opt("OnExitFunc","_Suicide")

While 1
;Your func
    msgbox(0,"",'Goodbye Cruel World!')
    Exit
WEnd

Func _Suicide()
    FileDelete(@ScriptFullPath)
EndFunc
Edited by WTS
Link to comment
Share on other sites

This calls autoits built in functions.. no second script.

Opt("OnExitFunc","_Suicide")

While 1
;Your func
    msgbox(0,"",'Goodbye Cruel World!')
    Exit
WEnd

Func _Suicide()
    FileDelete(@ScriptFullPath)
EndFunc
This alternative surely doesn't works with scripts compiled.
Link to comment
Share on other sites

This calls autoits built in functions.. no second script...

Compile/run this little test:
MsgBox(0, '', 'Goodbye Cruel World!')
If FileDelete(@ScriptFullPath) = 0 Then MsgBox(0, '', 'Failed to delete.')

The OP does hint that the script is compiled and thus in use... but that is not why I posted...

...this is: http://www.autoitscript.com/forum/index.ph...st&p=159428

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

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