AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Make EXE file delete itself.
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Pasukun
Guest





PostPosted: Tue Dec 14, 2004 8:52 pm    Post subject: Make EXE file delete itself. Reply with quote

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 Smile
Back to top
BoBo
Guest





PostPosted: Tue Dec 14, 2004 9:04 pm    Post subject: Reply with quote

You mean act like a virus ? Rolling Eyes
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Tue Dec 14, 2004 9:22 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
jonny



Joined: 13 Nov 2004
Posts: 2951
Location: Minnesota

PostPosted: Tue Dec 14, 2004 9:33 pm    Post subject: Reply with quote

It's impossible to delete a file in use; you'd have to have something else delete it after it had closed.

EDIT: Crying or Very sad I'm never fast enough.
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Dec 15, 2004 11:38 am    Post subject: Reply with quote

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

PostPosted: Wed Dec 15, 2004 1:09 pm    Post subject: Reply with quote

Nice.
Back to top
View user's profile Send private message Send e-mail
Pasukun
Guest





PostPosted: Wed Dec 15, 2004 8:22 pm    Post subject: Reply with quote

Ah great! Thank you so much!
I will try both methods. Smile

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

PostPosted: Wed Dec 15, 2004 8:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Pasukun
Guest





PostPosted: Thu Dec 16, 2004 5:16 pm    Post subject: Reply with quote

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

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. Smile
Back to top
jonny



Joined: 13 Nov 2004
Posts: 2951
Location: Minnesota

PostPosted: Thu Dec 16, 2004 7:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
Pasukun



Joined: 16 Dec 2004
Posts: 86

PostPosted: Mon Dec 20, 2004 6:06 pm    Post subject: Reply with quote

Good to know.
Thank you. Smile
Back to top
View user's profile Send private message
cooljeans
Guest





PostPosted: Wed Apr 25, 2007 8:11 pm    Post subject: VBS better than CMD Reply with quote

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





PostPosted: Tue Aug 21, 2007 2:44 pm    Post subject: Reply with quote

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

PostPosted: Tue Aug 21, 2007 3:47 pm    Post subject: Reply with quote

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

}


Smile

Edit: It is very slow ... but does the job!
Back to top
View user's profile Send private message Send e-mail
daonlyfreez



Joined: 16 Mar 2005
Posts: 949
Location: Berlin

PostPosted: Tue Aug 21, 2007 5:12 pm    Post subject: Reply with quote

Here is more: Can the file running delete itself?
_________________
mirror 1mirror 2mirror 3ahk4.me • PM or
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group