I have a main computer that knows when there is a power outage. That main computer will then tell all workstations to shutdown over the network using the built in "shutdown /m \computername /s" command.
That main computer will also tell individual workstations to restart using the same shutdown /m \\computername /r
mechanism.
Each workstation has a script that when executed, saves all the important data.
Each workstation has to execute its script when being told to shutdown or restart over the network (shutdown /m \\computername /s
or shutdown /m \\computername /r
).
Idea1:
- Use the WM_QUERYENDSESSION event to find out when a shutdown/restart occurs.
- Cancel the shutdown/restart.
- Run the script.
- Continue shutdown/restart (Problem: I don't see a reasonable way to determine if a shutdown or a restart has been issued by the main computer.)
Idea2:
- Wait until the shutdown.exe process exists.
- Retrieve the command line parameters of that process
- Kill that process
- Run the script.
- Run shutdown.exe with the retrieved parameters.
Problem: shutdown.exe isn't actually getting executed. Not even if you locally run a simple shutdown -s -t 30
.
Idea3:
- Sniff incoming network traffic.
- Look for shutdown -m packets
- ...
Problem: I have no idea what protocol is being used and how the packets are formatted.
Idea4:
- Monitor event logs
- Hope that it contains informations about what kind of shutdown has been issued
Problem: I have no idea if and where this would be logged.
PS:
I don't want to use PsExec. The workstations have to execute their scripts on their own.