Is there any way of detecting as to whether my system started by manually pressing the power button or did it start because of a Wake-On-LAN packet??Can i store this value somewhere and use it programmatically??
1 Answer
In Windows, the wake source is logged in the System Log. I'm not sure if it specifically logs your WOL-packet as a source, but you'd have to try for yourself as there are different systems in place which why the method described below is not fail-proof. (I hope all the English terms are correctly translated as I am using a Dutch copy of Windows. Therefore, if you can't find something, look for anything remotely similar! ;-))
The manual, human way:
- Find the System Log by opening up the run dialog by pressing Win + r. Enter eventvwr.msc and then run.
- On the left, open up Windows Logs and then System.
- Right-click System and select Filter Current Log...
- In the dialog that pops up, under Event Sources, select Power-Troubleshooter and click OK.
It should now list all power-related log entries. If you click one, the General tab should also list the Wake source.
Example through PowerShell:
System logs can be accessed through PowerShell. The below command on PowerShell will return the last log entry about power containing the "Wake Source". Adapt it to your needs. (Regex that stuff!)
Get-EventLog "System" | Where-Object {$_.source -like "*Microsoft-Windows-Power-Troubleshooter*"} | select -first 1 | Format-List
-
in the general tab the wake source is being displayed as unknown Jul 14, 2015 at 10:23
-
@NishantDwivedi That can on itself be used as a source, since there won't be many unknown sources. Unless you're using very niche ways of powering on your system, of course... It's not fail-proof... But then again, I don't know what you need it for.– PylsaJul 14, 2015 at 10:26
-
I tried this a few times today and the results are very hit and miss... I put my computer to sleep a number of times and woke it up using the power button, mouse, keyboard and WOL... none of which were entered in the Event Viewer (and subsequently filtered using above)... coincidentally, the only place that did show a result was cmd
powercfg -lastwake
but this only showed the WOL (my network adapter) - which was my first test... Jul 14, 2015 at 10:29 -
@BigChris odd... My log shows if it's an HID or power button all the time. Could this be related to differences between mainboards?– PylsaJul 14, 2015 at 10:34
-
1Probably is motherboard related because I just tried it again and the only entries in Event Viewer are the system going TO sleep... nothing about being woken up... it may be worth the answerer noting that different hardware may not make this solution 100% reliable... Jul 14, 2015 at 10:44