Jeremy D Pavleck
Jeremy D Pavleck

Reputation:

WMI & Computer power settings - Date/Time last out of standby

I'm trying to find out the last time a computer came out of standby/hibernate. I know I could get this by watching Win32_PowerManagementEvent, but that doesn't work in this instance as I need something I can poll - any ideas? It doesn't have to be WMI, I'm just assuming that's the place it would be.

Thanks!

Upvotes: 0

Views: 2651

Answers (2)

shadowz1337
shadowz1337

Reputation: 889

Awesome, thank you for this solution! I managed to get my script working using yours as a template. I can just run this using Task Scheduler.

Register-WMIEvent -query "Select * From Win32_PowerManagementEvent where EventType=4" `
 -sourceIdentifier "Action Before Sleep" `
 -action {
    write-host "Sleeping time!"
    nircmd.exe speak text "Remember Keyboard cover"
      }
      
#Get-EventSubscriber
#unregister-Event -subscriptionid 3

Upvotes: 0

Jeremy D Pavleck
Jeremy D Pavleck

Reputation:

Actually, as it usually happens, I figured this out as soon as I posted it.

So, to watch for when a computer comes out of standby, which is EventType 7 in Win32_PowerManagementEvent I used Powershell.

Register-WmiEvent -query "Select * From Win32_PowerManagementEvent where EventType=7" -messagedata "Power Management Resume" -sourceidentifier "Resume"

Then I went into and came back out of standby, and did Get-PSEvent, which showed my event I created. I could have just used -action to assign a scriptblock to run when that event occurs, but I was looking for something to poll.

Upvotes: 2

Related Questions