Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 0 down vote accepted

There's nothing built into the OS, but you can get a dev to code something for you...you 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") 
Return 

WM_POWERBROADCAST(wParam, lParam) 
{ 
   ; PBT_APMQUERYSUSPEND = 0 
   ; PBT_APMRESUMESUSPEND = 7 
   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

 
discard

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