Ronnie has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys I've opened my big mouth and landed myself in it (again)! Being a bit of a cheerleader for Perl I responded positively when asked if I thought Perl could be used to solve a common problem that we have! Having looked through cpan for modules that may perform this task I may have to eat my words unless some very helpful monk can point me in the right direction. We have 800 PC's (running Windows XP) that require to be updated with application software every time a new release comes our way. As these PC's are spread out all over the country we need a script that is to be run several nights in a row to establish whether or not we can switch these PC's on and off remotely. Over a period of a week or so any PC that can't be switched on and off remotely will get a personal visit from a man with a big spanner to try and resolve this problem. Once all 800 PC's are accessable we can update them all over night and voila happy customers all! I've found modules that ping remote PC's and Net::Wake which may be what I need to awaken a PC but nothing to put it back to sleep. Can anyone give me a pointer/hint on how to accomplish this task?

Replies are listed 'Best First'.
Re: Switching on & Off
by BrowserUk (Patriarch) on Sep 18, 2006 at 16:14 UTC

    To 'switch off' an XP machine, you'll probably need to use Win32::API to call InitiateSystemShutdown(Ex) on the remote machine. This will require domain admin priviledges.


    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".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Someone mention me? :)

      -ex

Re: Switching on & Off
by andyford (Curate) on Sep 18, 2006 at 16:17 UTC
    Judging from my experience of dealing with many systems and trying to keep them all updated in various ways, your strategy of waiting for all the PCs to be up at one time is probably gonna delay your software deployments. You're better off just updating whoever is available, and keep a log.

    Break your PC repairs out to a different task, you may never get all 800 working at one time!

    andyford
    or non-Perl: Andy Ford

Re: Switching on & Off
by burningdog (Scribe) on Sep 18, 2006 at 16:41 UTC
    I would check out WMI (Windows management interface). Using that you can access a lot of windows internals, it's mostly read only stuff but there is plenty you can do with it. I have used it before from perl with a decent amount of success. Just do a search for perl and WMI for some examples out there. Microsoft’s docs are obviously not geared towards perl but once you get basic communication going with WMI the docs will be clearer.
      WMI is *definitely* a good way to go. I have used it (via Tcl/Tcom, so it does work outside of MS languages / tools) to audit OS and software on remote machines and also to install software on remote machines - more as a proof of concept, and not as many as 800 machines, but it definitely works. You can run remote applications, reboot machines, etc. as long as you have the correct privileges.
Re: Switching on & Off
by andyford (Curate) on Sep 18, 2006 at 16:10 UTC
    I think that "going to sleep" would be a function of inactivity over a certain period of time so as to not cut someone off while they're trying to work. If the PCs are going to sleep on their own now, why not just let them keep doing it?

    andyford
    or non-Perl: Andy Ford

Re: Switching on & Off
by Anonymous Monk on Sep 18, 2006 at 18:46 UTC
    Why not modify their start scripts (or create them if they don't have them) to call a central server for an update. That way, all you need do is have the users shutdown one night, and the next restart get the script to load the new software.
    see
    http://www.microsoft.com/technet/prodtechnol/windows2000serv/maintain/optimize/startw2k.mspx

    Otherwise you might need something like dameware to individually access the machines, but it still needs to be loaded.
Re: Switching on & Off
by NetWallah (Canon) on Sep 18, 2006 at 16:08 UTC
    I have not tried this, but (assuming you use Active directory), the Energy star EZ GPO policy looks like it woud do the job.

         "For every complex problem, there is a simple answer ... and it is wrong." --H.L. Mencken

Re: Switching on & Off
by gregor-e (Beadle) on Sep 20, 2006 at 20:37 UTC
    fun-o-matic is a free, open source software suite written in perl that manages game center PCs. It allows remote control of bootup, shutdown and central monitoring, as well as a bunch of other stuff.