Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Deleting a running script

by waswas-fng (Curate)
on Sep 16, 2003 at 16:13 UTC ( #291866=note: print w/replies, xml ) Need Help??

in reply to Deleting a running script

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


Replies are listed 'Best First'.
Re: Re: Deleting a running script
by Bagarre (Sexton) on Sep 16, 2003 at 16:24 UTC
    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:
      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?


        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?

        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
      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 which is not a perl solution but perhaps there is a way to do this with one of the Win32 modules on CPAN

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://291866]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2022-01-16 22:16 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (50 votes). Check out past polls.