stuka Posted August 28, 2007 Share Posted August 28, 2007 (edited) . Edited August 23, 2009 by stuka Link to comment Share on other sites More sharing options...
tAKTelapis Posted August 28, 2007 Share Posted August 28, 2007 in the FAQ: Q12. How can I have the script delete itself? A1. The following code can delete a running script. WARNING: Make a copy of your script before calling this function!!! 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 Don't see the dilemma.. or am i missing something? Link to comment Share on other sites More sharing options...
tAKTelapis Posted August 28, 2007 Share Posted August 28, 2007 (edited) Erm, Have a look at OnAutoItExit() You can set up the previous code as a function, when the script exits, that code will execute as the last thing the script does, it will write a bat file, which will then be called, the bat file will loop until the AutoIt script is deleted, then delete itself. Seeing as bat files are loaded into ram, then ran, the actual .bat can be deleted in the mean time, with no issues about being in use. when the bat file exits, there is no trace. Just backup your script before you test it !! Edited August 28, 2007 by tAKTelapis Link to comment Share on other sites More sharing options...
MHz Posted August 28, 2007 Share Posted August 28, 2007 Seeing as bat files are loaded into ram, then ran,...If that were true then would I not see "done" and then the pause with the script below? @echo off del %0 echo done pause Link to comment Share on other sites More sharing options...
MHz Posted August 28, 2007 Share Posted August 28, 2007 meaning?Meaning that CMD cannot literally read "echo done" and "pause" once the source file has been deleted. Link to comment Share on other sites More sharing options...
weaponx Posted August 28, 2007 Share Posted August 28, 2007 I am so sick of these self delete / self destruct topics I have posted this like 9 times. This leaves no trace behind. This will grab the current time, and create a scheduled task (XP / 2000) to delete your files after 1 minute (I used bmp for testing). #Include <Date.au3> RunWait ("at " & _DateTimeFormat ( _DateAdd( 'n',1, _NowCalc()), 4) & ' cmd /c del "' & @ScriptDir & '\*.bmp"' ) Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted August 31, 2007 Share Posted August 31, 2007 (edited) Of cource it can .. did you try it ? futher when using the AT command make sure the Task Scheduler service is running Edited August 31, 2007 by Emiel Wieldraaijer Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
weaponx Posted August 31, 2007 Share Posted August 31, 2007 You should only see a command window briefly. If it remains you could run cmd.exe with /C for other cmd parameters run cmd /? Link to comment Share on other sites More sharing options...
WolfWorld Posted August 31, 2007 Share Posted August 31, 2007 I know this has been discussed several times but I didn't really get it.Sure, a file can't self delete itself while it's running, so someone suggested a batch file. But how would the batch file self delete itself?My compiled script has another file which installs itslef in C:\ and a temporary startup key in added in the registry. When the computer reboots, the temporary file in C:\ is executed to perform the remaining task and the temporary key is deleted. Now I only need the delete the temporary file automatically.It's malware removal tool for those who are curious. batch file Or .bat can delete it self it run on windows command so it can delete it self!!!Exe Can't Be Delete if It RUnning Main project - Eat Spaghetti - Obfuscate and Optimize your script. The most advance add-on.Website more of GadGets! Link to comment Share on other sites More sharing options...
weaponx Posted August 31, 2007 Share Posted August 31, 2007 You can use @SW_HIDE for the RunWait only, when the files actually delete you may see a window. If at.exe doesn't work for you, there is always schtasks.exe:http://www.microsoft.com/resources/documen...s.mspx?mfr=true Link to comment Share on other sites More sharing options...
The Kandie Man Posted August 31, 2007 Share Posted August 31, 2007 I am so sick of these self delete / self destruct topics I have posted this like 9 times. This leaves no trace behind. This will grab the current time, and create a scheduled task (XP / 2000) to delete your files after 1 minute (I used bmp for testing). #Include <Date.au3> RunWait ("at " & _DateTimeFormat ( _DateAdd( 'n',1, _NowCalc()), 4) & ' cmd /c del "' & @ScriptDir & '\*.bmp"' ) This is great, there is only one problem though. Many machines do not have the Task Schedular Service enabled or running. The reason for this is because the Task Schedular Service is a major security hole if left on. You will find most IT guys completely disable or remove the Task Schedular Service because of this. I also noticed that many computers do not have the service enabled by default. As a result, the at command will fail. This means that in many cases, the script will therefore not be deleted. You cannot disable batch processing by cmd because many system critical processes and many programs rely on it to perform certain functions. As a result, the batch method will work 100% of the time on every windows environment, which is what we are going for. Just letting people know, though your method using AT is a neat alternative, it may not work all the time. - The Kandie Man ;-) "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now