WMI 和 计算机电源设置 - 上次退出待机状态的日期/时间

发布于 2024-07-09 12:01:42 字数 154 浏览 14 评论 0原文

我试图找出计算机上次退出待机/休眠状态的时间。 我知道我可以通过观看 Win32_PowerManagementEvent 来得到这个,但这在这种情况下不起作用,因为我需要一些可以轮询的东西 - 有什么想法吗? 它不一定是 WMI,我只是假设它就在这个地方。

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城旧梦 2024-07-16 12:01:42

事实上,就像通常发生的那样,我一发布就明白了这一点。

因此,为了监视计算机何时退出待机状态,即 Win32_PowerManagementEvent 中的 EventType 7,我使用了 Powershell。

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

然后我进入并退出待机状态,并执行 Get-PSEvent,这显示了我创建的事件。 我本来可以使用 -action 来分配一个脚本块在该事件发生时运行,但我正在寻找要轮询的内容。

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.

千紇 2024-07-16 12:01:42

太棒了,感谢您提供这个解决方案! 我设法使用您的脚本作为模板来运行我的脚本。 我可以使用任务计划程序运行它。

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文