Search code examples
windowswindows-7remote-accessshutdown

How can you tell when a windows 7 machine is fully shutdown remotely?


I am working with 4 computers. Shutting off computer #1 will turn the power off to the other 3 computers. My task is to write a program to allow a user to shut off all four computers with one click.

In order to do this, I have to be able to let computer #1 know when the other computers are completely shutdown so it will know it is safe to shut itself off. This is further complicated because windows updates installing on shutdown means that the time it takes for a PC to shutdown is variable.

Is there a way I can tell if a computer is completely shutdown and finished with updates in code, over a network?

Edit: I tried to ping during an update and unfortunately I did not get a response during the later stages of the update.

Edit 2: Meatspace's suggestion of looking at reboot.xml and pending.xml is helpful. However instead of trying to predict how long an update will take I will check for pending updates using these files and if there are any I will restart computers 2, 3, and 4 instead of shutting them down. After all three have restarted I will send a signal to computer 1 to shutdown in 5 min while having computers 2, 3, and 4 shut themselves down.


Solution

  • Assuming that all four computers are connected to the network regularly (i.e., don't ever have a huge batch of updates), you could just have 1 wait 30 minutes (or whatever you think is appropriate) after sending shutdown commands to 2, 3, and 4.

    Like you said, the updates further complicate things, and I question whether it's worthwhile, but:

    • Pending updates can be found in C:\Windows\WinSxS\reboot.xml and C:\Windows\WinSxS\pending.xml, so you could have your script check there before shutting down and apply a variable-length timer based on their contents or lack thereof

    If you don't care about the updates being applied during any particular reboot, there are a lot of options to disable automatic updates and/or use the default shutdown behavior.

    I don't think you can ping a computer when it's updating, but I would like to know myself.