views:

154

answers:

3

We have a nightly process that updates applications on a user's pc, and that requires bringing the application down and back up again (not looking to get into changing that process).

The problem is that we are building a Windows AppBar on launch which requires a valid screen, and when the system is locked there isn't one in the Screen class. So none of the visual effects are enabled and it shows up real ugly.

The only way we currently have around this is to detect a locked screen and just spin and wait until the user unlocks the desktop, then continue launching. Leaving it down isn't an option, as this is a key part of our user's workflow, and they expect it to be up and running if they left it that way the night before.

Any ideas?? I can't seem to find the display information anywhere, but it has to be stored off someplace, since the user is still logged in.

The contents of the Screen.AllScreens array:

** When Locked:

Device Name    : DISPLAY
Primary        : True
Bits Per Pixel : 0
Bounds         : {X=-1280,Y=0,Width=2560,Height=1024}
Working Area   : {X=0,Y=0,Width=1280,Height=1024}

** When Unlocked:

Device Name    : \\.\DISPLAY1
Primary        : True
Bits Per Pixel : 32
Bounds         : {X=0,Y=0,Width=1280,Height=1024}
Working Area   : {X=0,Y=0,Width=1280,Height=994}

Device Name    : \\.\DISPLAY2
Primary        : False
Bits Per Pixel : 32
Bounds         : {X=-1280,Y=0,Width=1280,Height=1024}
Working Area   : {X=-1280,Y=0,Width=1280,Height=964}
A: 

This screen lock problem is dependant on what version you are using, either XP which uses GINA that locks the screen and Vista which uses ContentProvider, both of these mechanisms are ultimately responsible for this.

The only way to see if the screen is locked, is a screensaver kicks in, (this can be easily queried by running a pinvoke to query SystemsParameterInfo, to find out if the Screensaver is active or not - SPI_GETSCREENSAVERRUNNING and SPI_GETSCREENSAVESECURE to determine if that will trigger GINA or Content Provider) when pressing WinKey + L to kick in the screensaver, after the specified period of time, if no activity, then GINA or ContentProvider kicks in and replaces the screen-saver with a lock screen... I have included two relevant links that was posted here about the secure logging information under Windows...

tommieb75
A: 

There is no clean solution for this, Windows doesn't provide a way to detect that the work station is locked and that the "wrong" desktop is active. You can only detect the session switch, sample code is here. To make this work, you're pretty much forced to include this code in the app and have it leave a breadcrumb that it could read back when it starts back up. Be sure to reset it after you used it once so that the app cannot get stuck permanently.

Hans Passant
A: 

It would require a little work, however you could utilize EnumDisplayDevices, EnumDisplaySettingsEx, MonitorFromPoint, GetMonitorInfo all from user32 and grab a screen shot of the device.

If the PC is locked, or if there is an active screen saver, then the screen capture is always a beige color. You could check for that condition to know the system is locked. This works on systems being RDPed into also (Thin client to XP VDI for example.)

At least that works in my environment. Code samples can be found by Googling.

Edwin Davidson