Find out how long ago the windows computer woke up
I have a backup server which gets waken up by a wake-on-lan packet, then pulls the files from the clients and then goes back to sleep again.
Sometimes I wake it up via WOL and want to keep it on for a couple of hours.
When in the meantime a backup gets triggered, then the backup script sends the server back to sleep, which I don't want, as I had the intention to send it to sleep manually.
I don't want to set/unset a flag in a file, but have the server know that this backup did start while the server was already on for at least a couple of minutes and therefore should not be sent to sleep.
I figured out that the network interface status dialog contains a "duration" field, which is a good indicator for how long this interface has been up, which equals the time the server has been awake.
How can I access that information programatically, preferably through a python script?
Solution 1:
Windows Event Logging tracks events like "system has resumed from sleep".
Check the Windows Dev Center example code on Querying for Event Information.
I've not used this first hand but you should be able to get there with Python too.