如何CreateProcessAsUser并使其成为前台窗口?
我尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的描述,听起来好像您正在尝试以提升模式启动其他进程。如果这就是您想要做的,则无法将其设置为前台窗口。事实上,非高架进程不允许以任何方式/形状/形式接触高架进程。
创建的进程必须负责实际将其自己的窗口设置为前台窗口。尝试使用传递给
CreateProcessAsUser
的STARTUPINFO
结构,设置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 toCreateProcessAsUser
, setting theSTARTF_USESHOWWINDOW
flag, and specifying a value ofSW_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.