将重点放在使用CreateProcessAsUser从系统服务启动的窗口 [英] Give focus to a Window launched from a system service using CreateProcessAsUser

查看:2641
本文介绍了将重点放在使用CreateProcessAsUser从系统服务启动的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个系统服务,使用方法 CreateProcessAsUser 启动应用程序。

I have a System service that launch an application using the method CreateProcessAsUser.

此服务使用模拟在活动会话中启动应用程序。应用程序正在启动它应该,我设法使窗口出现在前面使用:

This service uses impersonation to launch the app in the active session. The Application is launching as it should, I managed to make the window appears on the front by using :


SetWindowPos(& this-> wndTopMost,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);

SetWindowPos( &this->wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE );

但我不知道该怎么做可以有键盘焦点。即使应用程序在顶部,只要用户没有在窗口上敲击,键盘输入到我的应用程序下面的应用程序。

But I don't know what to do so the app can have the keyboard focus. Even if the app is on top, as long as the user hasn't clic on the window, the keyboard input goes to the application below my app.

推荐答案

让您的应用程序通过 RegisterHotKey ,然后通过 SendInput模拟键

Let your application register a (carefully chosen) HotKey via RegisterHotKey and then simulate the key via SendInput

在处理 WM_HOTKEY 消息,您应该能够偷取焦点。

In the processing of the WM_HOTKEY message, you should be able to "steal the focus".

Remenber: BAD 窃取重点,但我完全理解我的客户要求什么!部分。

Remenber: It's BAD to steal focus, but I fully understand the "what my client is asking!" part.

这篇关于将重点放在使用CreateProcessAsUser从系统服务启动的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆