Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically detect when the OS (Windows) is waking up or going to sleep

Background

My son likes to use his laptop when he's not supposed to and I just thought it would be handy if I could write an application that would email me whenever he opened / closed his laptop.

(I'd even settle for something that notified me when there was network traffic on the machine)

Question

How do you programmatically detect when an OS is waking up or going to sleep? I found this link from this related post. But that covers OS X. I'm looking for the same thing for Windows 7.

(I'd like to do this in Java, if possible, but I'd settle for C#/C++)

like image 497
gMale Avatar asked Dec 05 '22 23:12

gMale


1 Answers

Easiest way is not to write any code at all, even though this is stack overflow. Click Start, type Schedule and choose Scheduled Tasks. Set one up (click Create Task) and set a Trigger when the machine is unlocked. For the Action, have it send you an email.

new triggernew action

Repeat for startup and when a user logs in, if you want. Done.

like image 158
Kate Gregory Avatar answered Dec 08 '22 16:12

Kate Gregory