| View previous topic :: View next topic |
| Author |
Message |
Pasukun Guest
|
Posted: Tue Dec 14, 2004 8:52 pm Post subject: Make EXE file delete itself. |
|
|
I wrote a script and compiled it into a EXE file.
Is there a way to make that EXE file delete itself when the job is finished?
Thanks  |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Tue Dec 14, 2004 9:04 pm Post subject: |
|
|
You mean act like a virus ?  |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10716
|
Posted: Tue Dec 14, 2004 9:22 pm Post subject: |
|
|
| BoBo wrote: | | You mean act like a virus ? | There are many legitimate reasons for wanting this behavior. I think it's best if we give everyone the benefit of the doubt.
The answer is to wait until the EXE has finished running and then have some other process delete it. Tekl provided the following method, which should remove the EXE file the next time the system is rebooted:
| Tekl wrote: | | RegWrite, REG_SZ,HKEY_LOCAL_MACHINE,SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce,Application,%comspec% /c del /q "%A_ScriptFullPath%" |
You could also have the script create a bat file via FileAppend that the script launches right before it exits. Such a bat file could delete the script and probably itself. |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 2951 Location: Minnesota
|
Posted: Tue Dec 14, 2004 9:33 pm Post subject: |
|
|
It's impossible to delete a file in use; you'd have to have something else delete it after it had closed.
EDIT: I'm never fast enough. |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Dec 15, 2004 11:38 am Post subject: |
|
|
| Chris wrote: | | You could also have the script create a bat file via FileAppend that the script launches right before it exits. Such a bat file could delete the script and probably itself. |
That would be the best, write a batch file, but this works...
| Code: | ; DeleteSelf.ahk, compile to see it really work (it always worked as .ahk)
;
msgbox, 4, , Delete %a_scriptname%?
IfMsgBox, No, exit
;FileDelete, %a_scriptname% ; when I tried this it didn't work (for .exe)
Run, %comspec% /c del "%a_scriptname%"
exit ; when I don't exit here, it don't work
if errorlevel <> 0
msgbox, 16, , Error! File %a_scriptname% not deleted. Errorlevel: %errorlevel%
else
msgbox, File %a_scriptname% was deleted. Errorlevel: %errorlevel% |
...I had the errorlevel checks in initially for the FileDelete, then left em for the Run, but when I put exit in, it made the .exe quit before the del command finished...a race condition, but it works. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10716
|
Posted: Wed Dec 15, 2004 1:09 pm Post subject: |
|
|
| Nice. |
|
| Back to top |
|
 |
Pasukun Guest
|
Posted: Wed Dec 15, 2004 8:22 pm Post subject: |
|
|
Ah great! Thank you so much!
I will try both methods.
BoBo,
I needed it to self destroy in order to protect the information it contains.
Such as an admin password for auto remapping of the remote harddrive at the bootup.
To counter measure the illegal use of the file.. I made the script to check the local computer's nodename, IP address, MAC address and handful of hidden fake files.
And if any of those information mismatches.. I want the file to(if possible) move itself to differnt location and rename itself and finally delete itself to reduce the risk of possible recovery. |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 2951 Location: Minnesota
|
Posted: Wed Dec 15, 2004 8:57 pm Post subject: |
|
|
| You may want to know that Windows file deletion is very incomplete... many utilities exist to recover "lost" data. To truly delete the file, download a shredding utility. |
|
| Back to top |
|
 |
Pasukun Guest
|
Posted: Thu Dec 16, 2004 5:16 pm Post subject: |
|
|
Yeah.. I use Sdelete.exe from sysinternals.com to delete the files for good.
However, the machine that has the illegal copy of the file most likely will not have such utility.. , so currently I am trying to use FileAppend and FileMove commands to create multiple fake files with garbage information and move them on top of the original file to overwrite it.
Then relocate the file, rename it, and finally delete it.
If you know some other good method to secure the file please let me know.
BTW, I was just wondering.. how secure is the AHK to EXE converter?
I know it has password protection, but can it be easily reverse engineered?
Thanks in advance.  |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 2951 Location: Minnesota
|
Posted: Thu Dec 16, 2004 7:34 pm Post subject: |
|
|
| Quote: | | I know it has password protection, but can it be easily reverse engineered? |
No. It's extremely hard to "decompile" any binary unless there's already been a specfic method laid out to do it. From my experience, exe2ahk password protection is very secure. To make it totally unbreakable, even to you, just specify a long, random password. If you're really crazy about it, you could even write a script that uses Random, Transform, etc. |
|
| Back to top |
|
 |
Pasukun
Joined: 16 Dec 2004 Posts: 86
|
Posted: Mon Dec 20, 2004 6:06 pm Post subject: |
|
|
Good to know.
Thank you.  |
|
| Back to top |
|
 |
cooljeans Guest
|
Posted: Wed Apr 25, 2007 8:11 pm Post subject: VBS better than CMD |
|
|
save the following code as deleteme.vbs and call it from your file, it can delet the exe file and the vbs itself.
| Code: |
Wscript.Sleep 15000 'wait program finish running
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.GetFile("your .exe file which call this vbs file")
MyFile.Delete
'Delete the currently executing script
Dim objFSO 'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile WScript.ScriptFullName
Set objFSO = Nothing
|
|
|
| Back to top |
|
 |
Freddie Guest
|
Posted: Tue Aug 21, 2007 2:44 pm Post subject: |
|
|
I am trying to figure out how to use the code written by cooljeans. Can anyone assist? Can we name the file as dummy.exe and write the code again accordingly so that I know where to put in the filename and how to write my own code with my filename.
Also, has anyone figured out a better way to erase an exe file as all the methods given above seem a bit edgy.
Thank You!!! |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Tue Aug 21, 2007 3:47 pm Post subject: |
|
|
| Freddie wrote: | | I am trying to figure out how to use the code written by cooljeans. Can anyone assist? Can we name the file as dummy.exe and write the code again accordingly so that I know where to put in the filename and how to write my own code with my filename. |
Name the script as you may like it, but you have to compile and run the EXE to test:
| Code: | If A_IsCompiled {
FileAppend,
(
Wscript.Sleep 15000
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.GetFile("%A_ScriptFullPath%")
MyFile.Delete
'Delete the currently executing script
Dim objFSO 'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile WScript.ScriptFullName
Set objFSO = Nothing
)
, %A_Temp%\selfDelete.VBS
Run, %A_Temp%\selfDelete.VBS
ExitApp
} |
Edit: It is very slow ... but does the job! |
|
| Back to top |
|
 |
daonlyfreez
Joined: 16 Mar 2005 Posts: 949 Location: Berlin
|
|
| Back to top |
|
 |
|