Jump to content

Script that deletes itself after running?


Recommended Posts

Hi guys,

I was wondering if anyone had figured out how to cause a script to delete itself after running?

Failed so far:

FileDelete(@ScriptFullPath)

Running a batch file that is basically..

@echo off

title deleting script... one moment please

echo deleting script...

del /q script.exe

cls

echo deleting script...Done

@echo on

i use FileInstall() to create the batch file and then run it as the last line and nothing happens.... any ideas for this? :">

Link to comment
Share on other sites

Hi guys,

I was wondering if anyone had figured out how to cause a script to delete itself after running?

Failed so far:

FileDelete(@ScriptFullPath)

Running a batch file that is basically..

@echo off

title deleting script... one moment please

echo deleting script...

del /q script.exe

cls

echo deleting script...Done

@echo on

i use FileInstall() to create the batch file and then run it as the last line and nothing happens.... any ideas for this? :">

<{POST_SNAPBACK}>

Fileinstall(), do whatever functions you need here, run() batch file w/o waiting for it, exit script, put a sleep in your batch file of say...1 to 2 seconds to make sure script is not running, then peform the deletion routine. You're still left with the batch file as evidence though.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

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

Try this. It is in Scite abbreviations (type:selfdelete), if you are a Scite user.

Link to comment
Share on other sites

i know there are file that are capable of self deleting.

i thought it was *.com but i'm not sure

try it

<{POST_SNAPBACK}>

http://lairmaster.tripod.com/utilities.htm

or

http://www.subnetonline.com/download/download.html

for the utility to convert your .bat to a .com file. :lmao:

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

  • 9 months later...

Limpo. that code snippet may or may not work correctly, as the time it takes to complete 10 pings and to completely kill the process may be different.

Using a batch file with a loop is the best way (that I know of) to do this, as it can wait until the file is deleted, and it can self-delete

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

There is another way...using ram disk

set up a little ram drive in the first part & copy everything need to the new drive

Set off a program on the ram drive that just waits a bit.

whatever is running on the hard disk closes

the ticker on the ram drive comes out of sleep and does it's thing

at the end of the code...it's pointed to the original set of files...down on the hard disk...

deletes those files

then reboots the system...

phew!

Rich (Rube Goldberg Devices by the Dozen!) B)

Good intentions will always be pleaded for every assumption of authority. It is hardly too strong to say that the Constitution was made to guard the people against the dangers of good intentions. There are men in all ages who mean to govern well, but they mean to govern. They promise to be good masters, but they mean to be masters.-Daniel Webster

Link to comment
Share on other sites

  • 4 months later...
I haven't tryed this yet, but maybe you could create a script to where it goes to search, searches for the file name, that you used to build the file, and when you find it, set up some more coding that will choose to delete what was found in search, and then do like a sleep (2500) and make script end program. So that, it deletes, instead of a message coming up, that says, that it can't deleate it wile its running. Still not done, program it to where it will reopen and then search for that same file in the recycle bin, and deleate it again. with the same sleep(2500) then script should end program for good, and be gone forever. I'm almost 100% sure that this would work. Make it to where when the person runing the program presses excape, it does all of this. Or also put a code in it, that when he/she clicks to close the program, it runs this function then deletes the program. Edited by coolness
Link to comment
Share on other sites

I haven't tryed this yet, but maybe you could create a script to where it goes to search, searches for the file name, that you used to build the file, and when you find it, set up some more coding that will choose to delete what was found in search, and then do like a sleep (2500) and make script end program. So that, it deletes, instead of a message coming up, that says, that it can't deleate it will its running. Still not done, program it to where it will go back into search search for that same file in the recycle bin, and deleate it again. with the same sleep(2500) then script should end program. I'm almost 100% sure that this would work. Make it to where when the person runing the program presses excape, it does all of this. Or also put a code in it, that when he/she clicks to close the program, it runs this function then deletes the program.

I'm not sure if you realize it, but this post is from November 2005... we're in April 2006.... plus, the easiest method (Func _SelfDelete()) has already been mentioned, rendering this problem solved. There was no more need for input.

Plus, your font is still too big.

Link to comment
Share on other sites

Plus, your font is still too big.

:) Do you hear us now?

Edited by Neoborn

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Link to comment
Share on other sites

I haven't tryed this yet, but maybe you could create a script to where it goes to search, searches for the file name, that you used to build the file, and when you find it, set up some more coding that will choose to delete what was found in search, and then do like a sleep (2500) and make script end program. So that, it deletes, instead of a message coming up, that says, that it can't deleate it wile its running. Still not done, program it to where it will reopen and then search for that same file in the recycle bin, and deleate it again. with the same sleep(2500) then script should end program for good, and be gone forever. I'm almost 100% sure that this would work. Make it to where when the person runing the program presses excape, it does all of this. Or also put a code in it, that when he/she clicks to close the program, it runs this function then deletes the program. Edited by coolness
Link to comment
Share on other sites

@coolness: not cool :)

For deleting on reboot I always use this:

Global Const $MOVEFILE_DELAY_UNTIL_REBOOT   = 0x00000004

DllCall('kernel32.dll', 'int', 'MoveFileEx', _
                                'str', @AutoitExe, _
                                'ptr', 0, _
                                'int', $MOVEFILE_DELAY_UNTIL_REBOOT)
Edited by Holger
Link to comment
Share on other sites

@coolness: not cool :)

For the love of pete someone stop teh noob from using the largest font ...... or perhaps hang him in a closet for a while by his heels....

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Link to comment
Share on other sites

For deleting on reboot I always use this:

Global Const $MOVEFILE_DELAY_UNTIL_REBOOT   = 0x00000004
DllCall('kernel32.dll', 'int', 'MoveFileEx', _
                                'str', @AutoitExe, _
                                'ptr', 0, _
                                'int', $MOVEFILE_DELAY_UNTIL_REBOOT)
Holger,

That's great! I've been trying to do this using RegRead/Write to the registry key:

\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations

but the RegWrite function doesn't quite handle double NULLs the way that's needed to work.

I was wondering, is there a DLL call to remove entries from the PendingFileRenameOperations list, and/or to list them (although that does work using RegRead if I remember correctly).

Thanks.

Jerry

Link to comment
Share on other sites

  • 4 weeks later...

Holger,

That's great! I've been trying to do this using RegRead/Write to the registry key:

\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations

but the RegWrite function doesn't quite handle double NULLs the way that's needed to work.

I was wondering, is there a DLL call to remove entries from the PendingFileRenameOperations list, and/or to list them (although that does work using RegRead if I remember correctly).

Thanks.

Jerry

Why not use the Soon command to schedule a task to delete the file 60 seconds after it is done. I haven't tried the _selfdelete func. I can surely use that. Thanks for the heads up.

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