Detecting if the screensaver is active and/or the user has locked the screen in Windows

前端 未结 6 1054
遇见更好的自我
遇见更好的自我 2020-12-09 06:50

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

6条回答
  •  既然无缘
    2020-12-09 07:05

    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.

提交回复
热议问题