How to determine if the current Windows session is locked?

I have an application that runs every hour on a computer running Windows XP. For this application to work properly, you need to unlock the current session. So I was wondering if there is a way to find out if the current Windows session is locked or not with C # and .NET 3.5.

UPDATE: The application cannot listen for SessionNotification events. The application can be launched at any time and terminated upon completion.

Thanks!

+6
c # windows winapi
source share
3 answers

They are untested by me, but they look interesting. I would give them a test, but currently my Visual Studio looks less than happy.

+1
source share

I once used the GetForegroundWindow() function to determine if a splash screen was running. If the return value was NULL , then a screen saver is active (or, presumably, a locked workstation). Please note that this was in the early days of Windows NT, not documented to do this, and there is no guarantee that it will still do the same today.

Looking at the Win32 API link, you can use something like OpenInputDesktop() to get the HDESK current active desktop. If you cannot get a desktop descriptor or if it is different from the desktop of your thread, your application runs on a desktop that is inactive (and the workstation is probably either in a splash screen state or locked). There is no guarantee that this method will work, but it may be worth exploring.

0
source share

I answered a similar question here . I think that methods 2 and 3 can be improved to detect a locked state.

0
source share

All Articles