I've recently upgraded both my home theater (media center) PCs to Windows Vista. The default power management settings put the HTPCs to sleep after some period of inactivity -- a feature I had disabled when I was running XP MCE on those machines. I usually don't let my machines "sleep" because I often access them remotely over the network.
Apparently I'm easily distracted, because my immediate need to copy a file to my sleeping HTPC sent me off on a 2-hour mission to write a little app that would utilize my PCs' Wake On LAN (WOL) capabilities. This started out as a simple WinForms app with a TextBox for input (MAC address) and a "Wake Up" button. That took about fifteen minutes, because I had to research how WOL works, and the "Magic Packet" that tells the PC to wake up (in a nutshell: the packet consists of 6 bytes of 0xFF followed by the remote PC's MAC address repeated 16 times, for a total of 102 bytes).
By then I was excited about how easy and cool WOL is, and what else I could do with the app. Anyway, a couple hours later, I ended up with a simple app that can be run from the command line or as a GUI app. I don't want to have to remember or lookup MAC addresses every time I want to wake up a PC, so the app can store MAC/hostname combinations. When run from the command line, I can pass in either the MAC address, or the hostname (which looks up the MAC stored in the file).
User Interface:


Command Line:
(Note that I'm using a MessageBox to confirm that the WOL packet has been sent. At one point I was doing the confirmation via the Console, but having the WinForms .exe switch gears to run as a console app, grabbing the current console for I/O, etc. was messy, and ended up doing weird things to the command prompt when it was done. One of these days I might try to get the console output working the way I want it to.)

The actual WOL process is very straightforward in .NET (I used C#); I just tacked on some other bells and whistles like associating hostnames to MACs, automatically saving the list to a file, and allowing it to be run as a GUI or command line app. I plan to clean up the code and release it at some point. In the meantime, let me know if you're interested.
...
I'm a bit behind on my blog reading, and I just saw Jeff Atwood's post from Friday: Remotely Waking Up Your PC. He posted about this very same subject, and apparently he got into it for the same reason (he wanted to wake up his Vista HTPC) -- just a day earlier. Weird. As expected, Atwood has some good stuff to say about WOL (refer to his post for how to set up the PC to respond to the WOL Magic Packet), but I enjoyed writing the app myself, so I guess I'm glad I didn't see his post until today.
Atwood's closing statement is perfect:
"You know, I think there's an inspiring moral to this story: why get out of your chair and walk 20 feet when you can spend two hours figuring out how to do it without moving at all? It's a symbolic victory for lazy people everywhere."
Sunday, February 11, 2007
Wake On LAN
Posted by
jwyse
at
7:36 PM
Labels: .NET, Development, Media Center, Tips, Vista
Subscribe to:
Post Comments (Atom)
1 comment:
Awesome. Just what I was looking for!
Post a Comment