Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Deleting the Currently Running Script in Win XP

by Dru (Hermit)
on Oct 04, 2005 at 15:51 UTC ( #497303=perlquestion: print w/replies, xml ) Need Help??
Dru has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

Greetings. I'm looking for some assistance with a windows script that needs to do some stuff, then reboots and picks up where it left off after a reboot. Right before it reboots, I copy the script into the startup folder. I wrote the script so it knows if it has been rebooted or not (basically looks for the exisitence of itself in the startup folder) and performs the rest of the actions.

Anyway, I want to delete the script when I'm done, since it's in the startup folder, I don't want it to run everytime the machine reboots. I thought this would be a simple using Perl's "unlink" command, but I can't do that, since the script is open and trying to delete itself. So I thought I can schedule an at job (using Windows at utility) to run a few minutes after my script exits, but I believe at is only native to XP, not 2000, which many of the clients would be running.

I then hoped I would find something in CPAN, which I did, Schedule::At, but it doesn't support WinXP. Does anyone have any suggestions on how I can do this?

Thank you very much,
  • Comment on Deleting the Currently Running Script in Win XP

Replies are listed 'Best First'.
Re: Deleting the Currently Running Script in Win XP
by marto (Archbishop) on Oct 04, 2005 at 16:01 UTC

    You could put an entry in the registry to remove this script the next time the machine starts.
    Check out the RunOnce Key.
    Check out Win32::Registry, the documentation is pretty good.

    Hope this helps.

Re: Deleting the Currently Running Script in Win XP
by BrowserUk (Pope) on Oct 04, 2005 at 16:02 UTC

    Rather simpler would be to run an asynchronous perl one-liner at the end of the script that waits a couple of seconds for the script to terminate and then deletes it like this:

    P:\test>type #! perl -slw use strict; sleep 10; ## Simulate doing stuff ## Start an asynchronous perl one-liner ## sleep a couple of seconds and the delete the script ($0) system 1, qq[ perl -e"sleep 2; unlink'$0'" ]; P:\test>junk P:\test>dir Volume in drive P has no label. Volume Serial Number is BCCA-B4CC Directory of P:\test File Not Found

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re: Deleting the Currently Running Script in Win XP
by Jenda (Abbot) on Oct 04, 2005 at 16:53 UTC

    Yet another (untested) way would be to schedule the deletion to reboot

    use Win32::FileOp qw(DeleteAtReboot); DeleteAtReboot($filename);
    I do believe these deletions happen long before the scripts in Startup folder.

    XML sucks. Badly. SOAP on the other hand is the most powerfull vacuum pump ever invented.


      Thanks, that's exactly what I needed. I can see a really smart and good looking individual wrote this module :-).

      Also, I saw in your homenode that you wrote Mail::Sender but you don't talk too highly of it. I use this for any script that I must send mail with (which is quite a few) and it works great. You should give yourself more credit for it, it's really helped me.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://497303]
Approved by Corion
and the universe expands...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2018-07-16 03:29 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (330 votes). Check out past polls.