I\'m writing an app that at times will send notifications to the user in the form of toaster messages.
If the user is not there, he can\'t see the notification. So w
In researching this question I found a couple techniques that support detecting if the workstation is locked. One is really simple:
bool locked = Process.GetProcessesByName("logonui").Any();
This works because the logonui process is only running when the desktop is locked.
Another more complicated approach is to walk the system event log backwards looking for event ids 4800 and 4801. These indicate when a machine is locked and unclocked.
More detail can be found at:
https://superuser.com/questions/1170918/determine-remote-windows-screen-locked-or-unlocked-remotely
http://mctexpert.blogspot.com/2012/10/how-to-determine-if-client-on-your.html
The latter requires audit policies to be set which are the default anyways. I work in an enterprise IT organization so it's not a concern for me as I'm certain those settings are applied.