Sign in to follow this  
Followers 0
wakummaci

Script deleting it self

6 posts in this topic

I've already read the stickies and found the code below here:

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

It doesn't seem to be working.. Do I have to change any parameters in the script relating to mine? And if my script is only consists of a function can I insert it into it?

Do I have to make a hotkey for this? Thx for any help.

Share this post


Link to post
Share on other sites



The code works for me.

> Do I have to change any parameters in the script relating to mine?

No

> And if my script is only consists of a function can I insert it into it?

Yes

>Do I have to make a hotkey for this?

No


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

Share this post


Link to post
Share on other sites

The code works for me.

> Do I have to change any parameters in the script relating to mine?

No

> And if my script is only consists of a function can I insert it into it?

Yes

>Do I have to make a hotkey for this?

No

Could you show me an example for this script being inserted to another one? Maybe that would help..

Share this post


Link to post
Share on other sites

Could you show me an example for this script being inserted to another one? Maybe that would help..

Do you actually execute the function or you just added the code? Add the code at the bottom and in your program put osmething like

; Your code here.. 
_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

My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

...And if my script is only consists of a function can I insert it into it?...

The answer is yes - but that really does not tell me what your main script looks like. You do not have to have any User Defined Functions (UDFs) in your main script in order for it to work... unless you mean that you main script consists of a single line/function built into AutoIt like:

MsgBox(0, "", "")

MsgBox(0, "", "")

$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)oÝ÷ Ú«¨µéÚ
or several other ways including using the specail Func named OnAutoItExit()

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

Share this post


Link to post
Share on other sites

I can't remember but it was sometime ago when i came across an alternative 1 line script that does exactly what the above does as well.

What it did was it took the current computer time, added a minute to it and added a 'Task Job' in Windows so that the task will run after a minute which will delete the script.

I can't seem to find it back, any ideas? Thank you in advance.

Here is one place that it is hiding...

http://www.autoitscript.com/forum/index.ph...st&p=396490

...notice that I picked a link that tells you why it might not be a good idea.

I have the Task Scheduler service disabled on this laptop.... so the script fails.

As far as it being one line of code... :-)

... you would have to copy the UDFs that you need from the Date.au3 file.

If you use "include" - it adds 2890 lines of code to that "one line solution".


[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