[英]Check if computer is activated through Wake On Lan
I'm working on a solution where machines are activated through Wake On Lan after which System Center pushes updates to the client pc's (running Windows 7). 我正在开发一种解决方案,通过Wake On Lan激活机器,然后System Center将更新推送到客户端PC(运行Windows 7)。
Now I'm working at a script (PowerShell/C#), that checks if the machine should be shutdown after the updates finishes. 现在我正在使用脚本(PowerShell / C#),它检查更新完成后是否应该关闭机器。
If the machine is activated through Wake On Lan and no user has logged on to the machine since activation, the machine can be safely closed. 如果通过Wake On Lan激活机器并且自激活后没有用户登录机器,则可以安全地关闭机器。 Otherwise, the machine should stay on.
否则,机器应该继续。
Is there some way to check how the computer got activated? 有没有办法检查计算机是如何激活的?
Since Windows 7 (maybe Vista), when you wakeup a computer "Microsoft-Windows-Power-Troubleshooter" provide a log in the System event log giving the wake up source. 从Windows 7(可能是Vista)开始,当您唤醒计算机时,“Microsoft-Windows-Power-Troubleshooter”会在系统事件日志中提供一个日志,提供唤醒源。 Here are two events (taken on Windows 8 desktop, but i've got the same ones on my Window 7 laptop), the first one was generated by a WOL, the second was generated using the front face button :
这是两个事件(在Windows 8桌面上拍摄,但我的Window 7笔记本电脑上有相同的事件),第一个是由WOL生成的,第二个是使用正面按钮生成的:
So using PowerShell you can test : 所以使用PowerShell你可以测试:
(Get-EventLog -LogName System -Source "Microsoft-Windows-Power-Troubleshooter" -AsBaseObject | Sort-Object {$_.timegenerated} | select -last 1 ).Message
This way you have to parse the message (not so good) 这种方式你必须解析消息(不太好)
get-winevent -FilterHashtable @{"ProviderName"="Microsoft-Windows-Power-Troubleshooter";"id"=1} | Sort-Object {$_.timecreated} | select -last 1 | %{([xml]$_.ToXml()).Event.EventData.Data}
Remark : Microsoft-Windows-Power-Troubleshooter provider also exists on W2K8-R2, when I try to Wake On Lan one of my old server the WakeSourceType
is unknown. 备注: W2K8-R2上也存在Microsoft-Windows-Power-Troubleshooter提供程序,当我尝试唤醒我的旧服务器时,
WakeSourceType
未知。
This might not exactly be what you're looking for, but an alternative approach: 这可能不是您正在寻找的,而是另一种方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.