为每个进程、用户或会话的非交互式用户获取 Window Station?

发布于 2024-09-06 01:59:12 字数 497 浏览 7 评论 0原文

当使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我的影子我的梦 2024-09-13 01:59:12

在 WinXP/Win2K3 或更高版本上,您可以执行以下操作:

  1. 调用 WTSEnumerateSessions 来获取活动会话信息的列表(这还将为您提供与每个会话关联的窗口站名称)。
  2. 将会话 ID 传递给 WTSQueryUserToken。
  3. 将令牌传递给 GetTokenInformation 以获取用户的 SID。
  4. 将用户的SID传递给LsaLookupSids以获取用户名和域名。

另外,如果您想确定哪个会话是活动控制台会话,您可以将会话 ID 与 WTSGetActiveConsoleSessionId 的返回值进行比较。

但是,我建议使用从 WTSQueryUserToken 返回的令牌通过 CreateProcessAsUser 在目标桌面上启动进程,正如 Franci 提到的那样。您必须通过 DuplicateTokenEx 传递它,以将其从模拟令牌转换为主令牌,但它可以在 WinXP 或更高版本上运行,并且 Microsoft 将其记录为从 Vista 和 Windows 上的服务桌面启动交互式应用程序的“首选”方式。更高。

On WinXP/Win2K3 or higher, you could do the following:

  1. Call WTSEnumerateSessions to get a list of active session information (which will also give you the window station name associated to each session).
  2. Pass the session id to WTSQueryUserToken.
  3. Pass the token to GetTokenInformation to get the user's SID.
  4. Pass the user's SID to LsaLookupSids to get the user and domain names.

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.

情深如许 2024-09-13 01:59:12

您可以使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文