Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I scripts automatically before hibernation and after waking up form hibernation? I am searching for something similar to the Logon/logoff and startup/shutdown scripts feature.

share|improve this question
up vote 0 down vote accepted

There's nothing built into the OS, but you can get a dev to code something for need to capture the WM_POWERBROADCAST event that fires when the system changes state.

I found a sample script that works with AutoHotKey:

OnMessage(0x218, "WM_POWERBROADCAST") 

   FileAppend, "powerbroadcast", Z:\Temp\pokus.txt 
   If (wParam == 0) { 
      FileAppend, "suspend", Z:\Temp\pokus.txt 
      Return true 
   } Else If (wParam = 7) { 
      FileAppend, "resume", Z:\Temp\pokus.txt

You could replace "FileAppend" with another AutoHotKey command.

You could make something up in Powershell probably but until Powershell 2.0 is released the "run in the background" capability isn't the best. There is a Powershell example in this thread in any case.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.