How to shutdown Windows via the network from Linux

January 28th, 2008 Categories: HOWTO\'s

I have a situation where I have 1 large, 1000W UPS & 3 PC’s connected to it. But it’s a cheapo, so it only has one serial communications port, which is currently connected to my Linux SME 7.2 server. The 2 Windows XP machines won’t know if the power is out, or if the UPS’s batteries are dead. So, even though the UPS keeps all running well for short power spikes, it’s not ideal for blackouts. I’m planning on getting an inverter & some 12V 102AH batteries to extend the backup time, but don’t have the money for it right now.

So, I have to tell Windows XP to shutdown when the UPS’s batteries are running down.

To automate things, I need something that I can run from a script in Linux. The UPS has a shutdown script, which is rather convenient to use for this purpose. So, here’s what I’ll need:

….. this entry will continue as soon as I can figure out how to format text in WordPress like in a forum
EDIT: I have been able to format the text in WordPress, so now I can continue …..

  1. First off, we need something called Poweroff, which can be downloaded here – Poweroff can be installed as a service in Windows, and then be controlled from a remote PC with with either Poweroff itself, or telnet.
    WARNING Make sure your computer isn’t accessable via the internet, since Telnet commands are insecure!!
  2. Once you’ve installed Poweroff, it will place a red icon in the tool bar, next to the clock on the right hand side. From here, if you right click on it, you can quickly shutdown / reboot / hibernate / stand by / etc. By double clicking on it, you can configure various settings. Since we want our Linux server to remotely shutdown the Windows PC, we need to tick the option, “Allow remote control” on the right hand side. This enable the option, “Settings” – a button next to it. Click on the Settings button to set the password. A password is needed, otherwise it doesn’t work.
  3. The last part is to write a script on the Linux server to shutdown the PC. I have tried this with telnet, but it doesn’t work, so I have decided to use Netcat, or nc instead. First, I create a file with the Poweroff commands that I want to run, as follows:
    Let’s call the file remote_pc_shutdown. This assumes the PC in question is called remote_pc, if it’s called workstation, then the sample will use workstation_shutdown
    [php]
    password mypass
    action hibernate
    when immediate
    message Your PC will now hibernate
    doit
    [/php]
    From this script, you can see that I’m going to hibernate the PC. You need to enable this feature in Windows first, otherwise it doesn’t work.

    A full list of commands can be found on the Poweroff Website, at the bottom. There’s also some samples on how to use Poweroff from the Windows command line.
    Lastly, we write the nc script on the linux machine, as follows:
    [php]
    nc {remote_pc} 3210 | < remote_pc_shutdown
    [/php]

    And that’s it. Naturally, you can do more than hibernating the PC. Have fun

    Share and Enjoy:
    • Digg
    • Sphinn
    • del.icio.us
    • Facebook
    • Mixx
    • Google Bookmarks
    • De.lirio.us
    • email
    • Furl
    • laaik.it
    • LinkedIn
    • MySpace
    • Slashdot
    • StumbleUpon
    • Technorati
    • YahooMyWeb
    • Print
    • TwitThis
    Tags:
No comments yet.
You must be logged in to post a comment.