为每个进程、用户或会话的非交互式用户获取 Window Station?
当使用CreateProcessAsUser时,我们传递STARTUPINFO并且lpDesktop为NULL,目标是winsta0/default,即交互式用户的交互式桌面。
我希望在第二个非交互式用户(例如远程桌面用户)的另一个会话中定位窗口站。
我认为它不可能是 winsta0,因为它是为单个交互式用户保留的。
我在这里查看函数列表: http://msdn.microsoft.com/en -us/library/ms687107(v=VS.85).aspx
我可以枚举计算机上的窗口站,但如何识别哪个窗口站连接到哪个用户/进程/会话?
每个窗口站都连接到一个会话 每个进程都有一个目标窗口站
但是,例如,如果我有一个进程或会话 ID,我如何确定它与哪个窗口站关联?
When using CreateProcessAsUser we pass STARTUPINFO and with lpDesktop NULL, the target is winsta0/default, the interactive desktop of the interactive user.
I wish to target a window station in another session of a second, non-interactive user, say a remote desktop user.
I assume that it can't be winsta0 because that's reserved for the single interactive user.
I am looking at the function list here:
http://msdn.microsoft.com/en-us/library/ms687107(v=VS.85).aspx
I can enumerate window stations on the machine, but how do I identify which window station is connected to which user/process/session?
Each window station is connected to a session
Each process has a target window station
But how, for example if I have a process, or a session ID, do I determine which Window Station it is associated with?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 WinXP/Win2K3 或更高版本上,您可以执行以下操作:
另外,如果您想确定哪个会话是活动控制台会话,您可以将会话 ID 与 WTSGetActiveConsoleSessionId 的返回值进行比较。
但是,我建议使用从 WTSQueryUserToken 返回的令牌通过 CreateProcessAsUser 在目标桌面上启动进程,正如 Franci 提到的那样。您必须通过 DuplicateTokenEx 传递它,以将其从模拟令牌转换为主令牌,但它可以在 WinXP 或更高版本上运行,并且 Microsoft 将其记录为从 Vista 和 Windows 上的服务桌面启动交互式应用程序的“首选”方式。更高。
On WinXP/Win2K3 or higher, you could do the following:
Also, if you want to identify which session is the active console session, you can compare the session id to the return value of WTSGetActiveConsoleSessionId.
However, I would recommend using the token returned from WTSQueryUserToken to launch a process on the target desktop via CreateProcessAsUser, as Franci mentioned. You'll have to pass it through DuplicateTokenEx to convert it from an impersonation token to a primary token, but it works on WinXP or higher, and Microsoft documents it as the "preferred" way to launch interactive applications from the services desktop on Vista and higher.
您可以使用
GetUserObjectinformation
获取与该窗口站关联的用户的 SID。至于从进程中查找Window Station:
- 获取进程的顶级窗口句柄
- 枚举窗口站 (
EnumWindowStations
)- 枚举每个窗口站的桌面 (
EnumDesktops
)- 枚举每个桌面的窗口 (
EnumDesktopWindows
),直到找到匹配项。是的,这并不简单,但它应该可以解决您的问题。
注意:在Vista和Win7上,交互式用户不在winsta0中。 Winsta0 仅为系统和服务保留,交互式用户获得一个新的 Windows 工作站,并以(大部分)与 TS 用户相同的方式对待。
You can use
GetUserObjectinformation
to get the SID of the user associated with that window station.As for finding the Window Station from a process:
- Get the top-level window handle for the process
- Enumerate the window stations (
EnumWindowStations
)- Enumerate the desktops for each window station (
EnumDesktops
)- Enumerate the windows for each desktop (
EnumDesktopWindows
) until you find a match.Yeah, it's not a straightforward, but it should solve your problem.
Note: On Vista and Win7, the interactive user is not in winsta0. Winsta0 is reserved for the system and services only, the interactive user gets a new windows station and is treated the (mostly) same way as a TS users.