简体   繁体   English

检查计算机是否通过Wake On Lan激活

[英]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: 这可能不是您正在寻找的,而是另一种方法:

  1. On server side, remember when the WOL packet was sent 在服务器端,请记住发送WOL数据包的时间
  2. On client side, ask the server for the last WOL packet time 在客户端,请询问服务器最后一次WOL数据包时间
  3. On client side, check the uptime of the PC, eg using WMI for uptime in Powershell or Codeplex Uptime 在客户端,检查PC的正常运行时间,例如在PowershellCodeplex Uptime中使用WMI进行正常 运行时间
  4. Compare the two. 比较两者。 Maybe consider some delay for the hardware boot process. 也许考虑硬件启动过程的一些延迟。 I don't exactly know whether uptime is counted by hardware or software. 我不确切知道正常运行时间是由硬件还是软件计算的。
  5. For the logged on users, you can use WMI for logged on users from Powershell 对于已登录的用户,您可以从Powershell的登录用户使用WMI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM