Sign in to follow this  
Followers 0
pille24

Delete the file after running it?

8 posts in this topic

How can i delete my script, after I have run it?

I dont want another script to do it.

And FileDelete is obviously not working, as the Script itself is still running...

thx

Share this post


Link to post
Share on other sites



FileDelete("path") should work, but if it doesn't you can run a cmd and delete it that way.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

cheers that works!

@ending

it doesnt work with FileDelete...

Share this post


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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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]

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