如何将 Windows 服务连接到控制台会话
我一直在开发一个作为 Windows 服务运行的远程桌面应用程序,我想知道如何将该应用程序连接到特定会话,并允许它以位图形式检索用户的桌面,设置光标位置,发送鼠标单击以及控制台会话的键盘输入。
I've been developing a remote desktop application which runs as a Windows service, and I was wondering how I could connect the application to a specific session, and allow it to retrieve the user's desktop as a bitmap, set the cursor position, send mouse clicks, and keyboard input to the console session.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
SetThreadDesktop()
将服务中的线程上下文更改为用户桌面。SetThreadDesktop()
将桌面句柄作为第一个参数;要获取该句柄,请使用EnumDesktops()< /代码>
。
EnumDesktops()
将窗口站的句柄作为第一个参数;要获取该句柄,请使用EnumWindowStations( )
要了解 Window Station 和桌面的情况,请尝试阅读 此概述来自 MSDN。
最后,请谨慎使用此技术。与用户桌面交互的较高权限进程(即服务)是粉碎攻击的基础。
You need to use
SetThreadDesktop()
to change the thread's context in your service to the user's desktop.SetThreadDesktop()
takes a handle to the desktop as it's first parameter; to get that handle, useEnumDesktops()
.EnumDesktops()
takes a handle to the window station as it's first parameter; to get that handle, useEnumWindowStations()
To understand what's going on with Window Stations and Desktops, try reading this overview from from MSDN.
Finally, be cautious with this technique. Higher-privileged processes (i.e., services) interacting with the user's desktop are the basis for shatter attacks.