AutoHotkey Community

It is currently May 27th, 2012, 7:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: December 14th, 2004, 9:52 pm 
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 :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2004, 10:04 pm 
You mean act like a virus ? :roll:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2004, 10:22 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2004, 10:33 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
It's impossible to delete a file in use; you'd have to have something else delete it after it had closed.

EDIT: :cry: I'm never fast enough.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2004, 12:38 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2004, 2:09 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Nice.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2004, 9:22 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2004, 9:57 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2004, 6:16 pm 
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. :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2004, 8:34 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 20th, 2004, 7:06 pm 
Offline

Joined: December 16th, 2004, 11:45 pm
Posts: 89
Good to know.
Thank you. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: VBS better than CMD
PostPosted: April 25th, 2007, 9:11 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 3:44 pm 
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!!!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 4:47 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 6:12 pm 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 969
Location: Frisia
Here is more: Can the file running delete itself?

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: bobbysoon, BrandonHotkey, just me, sjc1000, Yahoo [Bot] and 74 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group