Jump to content
Sign in to follow this  
Nova

Script that deletes itself

Recommended Posts

Nova

I was searching through the forum when I found a topic about making a script delete itself.

This is done by making the script write a batch file that deletes the script and then runs the batch.

FileWriteLine("c:\byebye.bat", 'del "'& @ScriptFullPath & '"')
FileWriteLine("c:\byebye.bat", 'del c:\byebye.bat')
Run("c:\byebye.bat")

I have found that this script works when ur dealing with small ammounts of code.

But I want to use it in a script that is quite large.

I find when I run the script it creates the batch file and runs it but only deletes the batch file and not the script aswell

I think this is because the script takes longer to finish that it dose for the batch file to finish and the batch file cant delete the script while its running.

I know larry asked how to make the script loop and keep trying to delete the script untill its done and I have tryed to edit that sample script but cannot get it to work.

Can anyone show me how I can make the script loop the delete command untill the script deletes itself ?

Edited by nova

Share this post


Link to post
Share on other sites
Jos

This version has a loop back to the beginning until the del command was successful. The ping is to make it pause a few seconds.

FileWriteLine("c:\byebye.bat", ':start')
FileWriteLine("c:\byebye.bat", 'del "'& @ScriptFullPath & '"')
FileWriteLine("c:\byebye.bat", 'ping dummy')
FileWriteLine("c:\byebye.bat", 'If exist "'& @ScriptFullPath & '" goto start')
FileWriteLine("c:\byebye.bat", 'del c:\byebye.bat')
Run("c:\byebye.bat")

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Nova

I left out the ping because I though it was part of larrys program,and im guessing I must have damaged the code by doing so !

Tnx for teh quick reply JdeB I owe u 1 !

Edited by nova

Share this post


Link to post
Share on other sites
Jos

I left out the ping because I though it was part of larrys program,and im guessing I must have damaged the code by doing so !

Tnx for teh quick reply JdeB I owe u 1 !

the ping can be left out ... but the batch file will take a lot of CPU when the scriptfile can't be deleted...

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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  

×