【问题标题】:Bring UAC window to top using ShellExecuteEx()使用 ShellExecuteEx() 将 UAC 窗口置于顶部
【发布时间】:2016-01-30 01:28:00
【问题描述】:

我正在使用 Microsoft Visual Studio 2010,并且正在使用 C/C++ 编写代码。

我有自动启动安装过程的代码。在这种情况下安装过程需要UAC,所以我使用ShellExecuteEx() API函数和runas动词:

hWindow = InstallCreateWindow(NULL);

execInfo.cbSize         = sizeof(execInfo);
execInfo.lpVerb         = _strdup("runas");
execInfo.hwnd           = hWindow;
execInfo.lpFile         = szPath;
execInfo.lpParameters   = szParams;
execInfo.fMask          = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;

Sleep(1000);

SetActiveWindow(hWindow);

if(ShellExecuteEx(&execInfo))
    return execInfo.hProcess;

if(GetLastError() == ERROR_CANCELLED)
{
    // user answered NO to UAC prompt
}

InstallCreateWindow() 函数创建信息窗口并创建单独的窗口消息线程。窗口是可见的,最上面的,它响应消息。我必须创建它,因为我已经阅读了 SHELLEXECUTEINFO 结构中正确的 hwnd 参数才能将 UAC 提示窗口保持在顶部。

但这不起作用。有时 UAC 窗口会最大化运行,但主要是在任务栏中最小化并突出显示。有没有办法让 UAC 窗口置顶?

【问题讨论】:

  • 如果调用ShellExecuteEx的程序没有前台激活,则UAC对话框无法激活,只能等用户激活。
  • 你泄露了_strdup的字符串。
  • @JonathanPotter 用于测试,我会删除它。
  • 你正在用 C++ 编写
  • @deselect 主要在 C 中使用 C++ 是说 C++ 没有 C++ 特性的一种方式:P

标签: c winapi uac shellexecuteex


【解决方案1】:

只是为了将其标记为已回答

如果调用 ShellExecuteEx 的程序没有前台 激活,则 UAC 对话框无法激活,所以它必须 等到使用激活它。雷蒙德·陈

【讨论】:

    猜你喜欢
    • 2010-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 2020-11-11
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多