如何CreateProcessAsUser并使其成为前台窗口?

发布于 2024-10-18 22:17:23 字数 102 浏览 1 评论 0原文

我尝试使用 CreateProcessAsUser 启动 UI,但该窗口不是前台窗口。

如果它是一个普通窗口,我不介意,但这个窗口会触发 UAC 提示,并且它也不显示在前台。

I'm trying to start an UI using CreateProcessAsUser but the window doesn't come as the foreground Window.

I wouldn't mind if it was a normal window, but this window triggers the UAC prompt and it isn't displayed in foreground neither.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑白记忆 2024-10-25 22:17:23

根据您的描述,听起来好像您正在尝试以提升模式启动其他进程。如果这就是您想要做的,则无法将其设置为前台窗口。事实上,非高架进程不允许以任何方式/形状/形式接触高架进程。

创建的进程必须负责实际将其自己的窗口设置为前台窗口。尝试使用传递给 CreateProcessAsUserSTARTUPINFO 结构,设置 STARTF_USESHOWWINDOW 标志,并指定 SW_SHOWNORMAL 值。如果这不起作用,除了首先提升自己的一部分(例如创建提升的 COM 组件)之外,没有真正的解决方法。

如果这不是您想要做的,并且您只是想将子进程的窗口移动到前台,那么您必须 枚举子进程拥有的窗口,然后调用 SetForegroundWindow 其中之一。

From your description, it sounds as if you are trying to launch the other process in elevated mode. If that's what you're trying to do, you cannot set it to the foreground window. In fact, non-elevated processes aren't allowed to touch elevated processes in any way/shape/form.

The created process has to be responsible for actually making its own window the foreground window. Try playing with the STARTUPINFO structure you pass to CreateProcessAsUser, setting the STARTF_USESHOWWINDOW flag, and specifying a value of SW_SHOWNORMAL. If that doesn't work, there's no real workaround other than elevating part of yourself first, such as creating an elevated COM component.

If that's not what you're trying to do, and you simply want to move the child process' window to the foreground, then you have to enumerate windows owned by the child process and then call SetForegroundWindow on one of them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文