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 bitma开发者_开发知识库p, set the cursor position, send mouse clicks, and keyboard input to the console session.
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.
精彩评论