It really is not a perl question, but it is possible. On unix you may unlink the running program's file (on most versions of unix at least) and the file will be deleted (it still really exists until the proccess ends. I do not think you can do it the same way on windows platforms -- you may have to release control (exec) to another program that removes the exe that you were running. for windows that may mean execing cmd with the delete command in the exec string. one problem here is that if your exec fails for some reason you have no chance to recover...
The killer is, it's a Windoz platform.
Unlink would work like a charm if I was in a 'nix world.
Windows puts a lock on the file and I can't even 'manualy' delete it from the command prompt while she's running :(
I tried scheduling a job to do it for me just after the program finishes but, that opened another can of worms. I was hoping to take care of it from within the program itself.
waswas-fng gave you the answer. You need to have the last few lines of your program create a batch file. The batch file looks something like:
The final line of code would be:
Why is it important for the executable to delete itself anyway?
There is a way to do this by setting a value in the registry to run the program on the next reboot and then forcing a reboot on the system.
I can't offer any additional guidance since I am certainly no Windows Programming Guru....except to say that I know this can be done because I have seen it in commercial installer programs.
I found this artcle on forcing a reboot on http://www.devx.com/ which is not a perl solution but perhaps there is a way to do this with one of the Win32 modules on CPAN
I'm just grasping as straws here (if I were using windows myself, I guess I'd be gasping at flaws...) -- anyway, I wonder if you can figure a way to have your script manipulate the windows "task scheduler" so that it will execute some windowless process to delete your script file at, say, a minute or two after the current time when the script is about to exit. (Needless/heedless to say, "cron" on *nix would make this sort of approach very easy.) Good luck.
On windows you may execute an at job (see the at command) to run 5 minutes after the process completes -- do this right before your program would normally exit and delete the entire directory your malware is running from. This will resolve the dll left behind issue and is built into nt -> xp