How do I make the exe delete itself?
Moderators: JRL, Dorian (MJT support)
How do I make the exe delete itself?
Is this possible? it has to be!
A script (.SCP file) can delete itself because it is not the running process. That's not the case with an executable. An executable starts a running process and while its process is running can't be deleted.
So what you have to do is somehow end the process and still have a delete command issued by the executable lurking. You can do this by having the executable write then run a batch file that looks like this:
choice /C:~ /T:~,2
Del C:\path\executable.exe
The "2" at the end of the first line is the number of seconds that the batch file will wait until it processes the second line which should delete the specified file.
Be sure that rp_wait is set to 0.
So what you have to do is somehow end the process and still have a delete command issued by the executable lurking. You can do this by having the executable write then run a batch file that looks like this:
choice /C:~ /T:~,2
Del C:\path\executable.exe
The "2" at the end of the first line is the number of seconds that the batch file will wait until it processes the second line which should delete the specified file.
Be sure that rp_wait is set to 0.
Lookup the WriteLn> command in the Help File... or here on this website, from the Navigation menu at the top, click Support/Online Help... then click on Command Reference... then click on the WriteLn> command.Boxxxed wrote:How do I make the exe create a batch file?
Take care
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

I forgot that choice doesn't come with newer operating systems, I've been copying it upward for years. We can set a batch file delay using the ping command also. The "2" between the "-n" and the "-w" is the number of seconds of delay. The following will compile to "C:\DeleteThisExecutable.exe". The batch file is set up to delete "C:\DeleteThisExecutable.exe". The batch file also deletes itself. Unremark the rp_windowmode line to prevent the DOS window from appearing.
Code: Select all
// COMPILE_OPTS|C:\DeleteThisExecutable.exe||CONSOLE=0|INCLUDES=1|
WriteLn>c:\DeleteMe.bat,wres,PING 0.0.0.0 -n 2 -w 1000 >NUL
WriteLn>c:\DeleteMe.bat,wres,Del C:\DeleteThisExecutable.exe
WriteLn>c:\DeleteMe.bat,wres,Del C:\DeleteMe.bat
//Let>rp_windowmode=0
Let>rp_wait=0
Run>c:\DeleteMe.bat
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Another way would be to create and run a small .vbs file which sleeps for a while and then performs the delete. Or, assuming windows task scheduler is running, create a task to delete in a few mins time.
However, it should go without saying, that self-deletion is a dirty trick and isn't something you should do unless you have a very good reason. Also bear in mind that if the file/folder is marked as read only, or is in a location that the current user doesn't have write access to, the deletion will fail.
However, it should go without saying, that self-deletion is a dirty trick and isn't something you should do unless you have a very good reason. Also bear in mind that if the file/folder is marked as read only, or is in a location that the current user doesn't have write access to, the deletion will fail.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Not really true, even some version of adobe flashplayer also selfdelete itself after running.
BTW, heres one vbscript modify from a sample found on the internet.
[code]
Set objFSO = CreateObject("Scripting.FileSystemObject")
strScript = Wscript.ScriptFullName
objFSO.DeleteFile(strScript)
Wscript.Sleep 2000
objFSO.DeleteFile(yourexefilename)
[/code]
BTW, heres one vbscript modify from a sample found on the internet.
[code]
Set objFSO = CreateObject("Scripting.FileSystemObject")
strScript = Wscript.ScriptFullName
objFSO.DeleteFile(strScript)
Wscript.Sleep 2000
objFSO.DeleteFile(yourexefilename)
[/code]
- CyberCitizen
- Automation Wizard
- Posts: 724
- Joined: Sun Jun 20, 2004 7:06 am
- Location: Adelaide, South Australia