Run a script when Windows resumes from suspend/hibernate state?
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Underwater World
--
Chapters
00:00 Run A Script When Windows Resumes From Suspend/Hibernate State?
00:30 Answer 1 Score 2
00:59 Accepted Answer Score 16
01:55 Answer 3 Score 1
02:12 Thank you
--
Full question
https://superuser.com/questions/276054/r...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#windows7 #windows #windowsxp #script
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Underwater World
--
Chapters
00:00 Run A Script When Windows Resumes From Suspend/Hibernate State?
00:30 Answer 1 Score 2
00:59 Accepted Answer Score 16
01:55 Answer 3 Score 1
02:12 Thank you
--
Full question
https://superuser.com/questions/276054/r...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#windows7 #windows #windowsxp #script
#avk47
ACCEPTED ANSWER
Score 16
In windows 7, you can do this with a scheduled task. Setup a batch script to do the actions you want and then create a task with one of the following triggers:
- On workstation unlock - Ignores first log on, but will start after unlock.
- On connection to user session - Every log on, can be local or remote connection.
- On an event - In the system log, the "Power-Troubleshooter" Source will log an event code of 1 when you wake up from a sleep state.
I have not tested these to make sure that they work as expected, but I have used "On workstation lock" with high amount of success. From what I remember of scheduled tasks in XP, it only has "When I log on".
Hope this helps
ANSWER 2
Score 2
Using Win32_PowerManagementEvent? I just googled it and found the following script (no warranty;).
Set oShell = CreateObject("WScript.Shell")
Set colMonitoredEvents = GetObject("winmgmts:")._
ExecNotificationQuery("Select * from Win32_PowerManagementEvent")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
Select Case objLatestEvent.EventType
Case 4
oShell.Run "Calc.exe", 1, False
MsgBox "Entering suspend, Calc started", _
vbInformation + vbSystemModal, "Suspend"
Case 7
oShell.Run "Notepad.exe", 1, False
MsgBox "Resuming from suspend, notepad started", _
vbInformation + vbSystemModal, "Suspend"
Case 11
MsgBox "OEM Event happened, OEMEventCode = " _
& strLatestEvent.OEMEventCode
Case 18
MsgBox "Resume Automatic happened"
End Select
Loop
ANSWER 3
Score 1
Add a scheduled task with trigger: on workstation unlock. It works, I run it after wake up from sleep. Om my Windows 2008R2 box the audio service needs to be restarted, otherwise sometimes it uses 100% of 1 cpu.