How to programmatically bring UAC permission.exe to the fore?

How (if at all possible) to bring the Vista / Win7 UAC consent dialog to the forefront when it is minimized in the taskbar?

For example, consider the following scenario:
My application checks for updates at startup, it downloads a new update file and executes it, providing an administrator password in Process.StartInfo, after which my application closes.

At this point, if the user or Windows manages to lose focus from the MSI installer window (perhaps by clicking on the desktop or in another window), UAC sees that the installer window is not a foreground window and thus causes a blinking dialog agreement on the panel tasks.

Some not so bright clients do not understand that my application has not yet completed the update and will try to restart the application. At this point, I can list the current processes and find the consent file. That blinks on the taskbar.

The problem is that I cannot bring it to the fore. I tried calling ShowWindow () from user32.dll with different parameters (restore, show, normal), but nothing happens. I checked the MainWindowHandle process and it looks normal (it is not zero or negative). I assume the problem is that the UAC is creating another desktop for the consent dialog (secure desktop).

If the user can click the flashing icon on the taskbar to bring the consent dialog to the fore, then can it also be modeled using code?

PS! I am using c #

+4
source share
2 answers

Have you tried SetForegroundWindow ? In addition, native win32 is not actually called the main window, the process can have 0 or any number of โ€œmain windowsโ€, but in the case of the .exe convention, I assume that it has only one ...

Edit:

BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam) { char buf[50]; *buf=0; GetClassName(hwnd,buf,50); buf[sizeof("$$$Secure UAP")-1]=0; if (!lstrcmp("$$$Secure UAP",buf)) { SwitchToThisWindow(hwnd,true); } return true; } ... EnumWindows(EnumWindowsProc,0); 

This will switch to a secure desktop, but I would not recommend using this because:

  • It uses the undocumented class $$$ Secure UAP ...
  • Using SwitchToThisWindow is evil, you should never switch focus when the user does not want
  • If more than one UAC confirmation dialog is activated, you cannot be sure with which .exe convention you will switch to

The problem is that the consent window is not a popup if you could be sure you got the correct HWND. We hope that Win8 will agree that this will be an accessible pop-up window or even a better, modal dialogue.

+1
source

There is a discussion here that can help you: How do you enlarge the user account management (UAC) window?

The official documentation for this is here: Redesign for UAC Compatibility (UAC)

0
source

Source: https://habr.com/ru/post/1333277/


All Articles