How to bring UAC's consent.exe to the foreground programmatically?

[亡魂溺海] 提交于 2019-12-05 17:32:30

Did you try SetForegroundWindow ? Also, in native win32 there is not really anything called a main window, a process can have 0 or any number of "main windows" but in the case of consent.exe, I'm guessing it has just 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 the secure desktop, but I would not recommend using this because:

  • It uses the undocumented $$$Secure UAP... window class
  • Using SwitchToThisWindow is evil, you should never switch focus when the user does not want to
  • If more than one UAC confirmation dialog is active, you can't be sure which consent.exe you will be switching to

The problem is that the consent window is not a owned popup, if it was you could be sure you got the correct HWND. Hopefully Win8 will have consent act as a owned popup, or even better, a modal dialog.

There is a discussion here that may help you: How do you maximize User Account control(UAC) window?

The official documentation about that subject is here: Redesign for UAC Compatibility (UAC)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!