Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

Now I'm working at a script (PowerShell/C#), that checks if the machine should be shutdown after the updates finishes.

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. Otherwise, the machine should stay on.

Is there some way to check how the computer got activated?

like image 834
Wouter de Kort Avatar asked Jun 04 '14 07:06

Wouter de Kort


People also ask

How do I know if Wake-on-LAN is enabled?

Open the start menu and type "Device Manager" and open the device manager. Expand "Network Adapters" and right-click your network adapter (typically Intel) and select Properties. Click the "Power" or "Power Management" tab and make sure WOL is enabled.

Will Wake-on-LAN Turn on computer?

Wake-on-LAN (WOL) allows a computer to be powered on or awakened from standby, hibernate or shutdown from another device on a network. The process of WOL is the following: The target computer is in standby, hibernate or shutdown, with power reserved for the network card.

Does Wake-on-LAN need to be enabled in BIOS?

Wake-on-LAN must be enabled in the desktop board BIOS and then configured in the operating system. To enable Wake-on-LAN in the BIOS: Press F2 during boot to enter BIOS Setup.


1 Answers

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. 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 :

enter image description hereenter image description here

So using PowerShell you can test :

(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.

like image 124
JPBlanc Avatar answered Sep 19 '22 13:09

JPBlanc