in reply to Re: Re: Deleting a running script
in thread Deleting a running script

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:
del script.exe del batch.bat
The final line of code would be:
exec ("batch.bat");
Why is it important for the executable to delete itself anyway?


Replies are listed 'Best First'.
Re: Re: Re: Re: Deleting a running script
by bart (Canon) on Sep 16, 2003 at 17:13 UTC
    Why is it important for the executable to delete itself anyway?
    I'm pretty sure he's writing an uninstaller.

    Now, you surely wouldn't want any traces of an uninstalled program left, if it were on your system, no?

      or a virus.... Big bloody virus it would be though.




Re: Re: Re: Re: Deleting a running script
by Anonymous Monk on Sep 16, 2003 at 18:07 UTC
    The program is 'farmed' out and runs in the background without a gui or anything in order to not disturb or alert the user. (It's not a hacker tool. More of a config checker) Not alerting the user is a big ticket for this thing so, no pop-up windows or rebooting can be done. :( Once it's done, I dont want it floating around on the computers so, it needs to delete itself. I have the "Farmer" program going back around and removing it now but, I wanted a more elegant solution instead of constantly checking if the tool has finished.. blah blah. I tried the batch file method and back tic'd it to the shell but, always got a 'permission denied' due to the process locking the file. Thanks
      I think you forgot to login. The `batch.bat` method won't work. You have to exec. I verified that it works.

      Cheers - L~R

        Forgot to login?? exec kind of works but, plays havoc with the parent process. It causes it to exit abnormaly and leaves a slew of .dll files in the temp directory. (Perl2exe expands required modules as dll's) Which is just as bad for me. This is gonna drive me crazy! There has to be an elegant solution to this. Thanks anyway guys and gals.