Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a WinAPI message when a Windows UAC prompt is triggered?

When a UAC prompt is triggered (not by my application), it breaks certain things (I believe it to be Direct3D device handles) which causes the screen to show the last frame drawn instead of a moving image.

I did not write the code that displays the 3D image (it's a plugin), but after the UAC prompt, if I resize the window the image returns.

Is there a way to detect the UAC prompt closing so I can call code that will refresh the display to compensate?

like image 822
bLight Avatar asked Mar 07 '23 19:03

bLight


1 Answers

A UAC prompt is generally displayed on the secure desktop, so it is accompanied by a switch to a different desktop (cf. SwitchDesktop). Although you can turn this option off and not have UAC prompts cause a desktop switch, it's on by default for security reasons, and is almost certainly the reason why you're seeing any sort of visual disruption.

You can use the SetWinEventHook function, listening for the EVENT_SYSTEM_DESKTOPSWITCH event, in order to receive notification that this has occurred. You'll get some false positives, because other situations can cause a desktop switch, but it probably isn't a big deal to just go ahead and redraw in all of those cases.

This is a general solution, though, and may not work reliably. You aren't, in general, supposed to be able to detect when the secure desktop is visible, as that would open up a possible security hole.

The question doesn't specify which version of Direct3D you are using, but if it's a legacy version (Direct3D 9, for example), then this desktop switching will be handled as if the rendering device was lost. A better solution in your case is probably to install a handler for the lost-device notification (EC_DEVICE_LOST) so that you can respond properly, including re-establishing handles and forcing a redraw.

This shouldn't be a problem with modern versions of Direct3D, though, as they are written to be aware of desktop-switch events. UAC prompts are one common scenario that would lead to a desktop switch; locking the workstation is another. Both of these switch to the secure Winlogon desktop. The newer WDDM-aware versions of Direct3D (e.g., Direct3D 9Ex, or Direct3D 10 and later) should handle this seamlessly, without losing the rendering device and without experiencing any visual disruption.

like image 67
Cody Gray Avatar answered Apr 28 '23 23:04

Cody Gray