获取登录与桌面相关联的Windows用户名 [英] Get the logged in Windows user name associated with a desktop

查看:397
本文介绍了获取登录与桌面相关联的Windows用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要列举所有桌面系统中,并获得登录的用户名进行的桌面。到目前为止,我有以下的code SNIPPIT为获得HDESK把手,并试图确定它(如果有的话)关联的用户名的例子,但调用执行LookupAccountSid失败,ERROR_NONE_MAPPED(帐户名和之间没有映射安全标识已完成)。

I wish to enumerate all desktops in a system and get the logged in user name for that desktop. So far I have the following code snippit as an example of obtaining a HDESK handle and trying to determine the user name associated with it (if any), but the call to LookupAccountSid fails with ERROR_NONE_MAPPED ("No mapping between account names and security IDs was done").

HDESK desk = OpenDesktop( "Default", 0, FALSE, READ_CONTROL | DESKTOP_READOBJECTS );

DWORD size = 4096;

SID * sid  = (SID *)malloc( size );

GetUserObjectInformation( desk , UOI_USER_SID, sid, size, &size );

char name[512], domain[512];
int namesz = 512, domainsz = 512;

LookupAccountSid( NULL, sid, &name, &namesz, &domain, &domainsz, &s);

这可能是因为我拉出通过GetUserObjectInformation登录SID而不是用户的SID。如果是的话我可以转换到用户登录SID?

It might be because I am pulling out a logon SID via GetUserObjectInformation rather then a user SID. If so can I convert that to the logged in users SID?

任何人都可以点我在正确的方向对于获取登录的用户名任意桌面(通过它要么各自的HDESK或HNWD把手,甚至是桌面的站HWINSTA手柄)?在此先感谢

Can anybody point me in the right direction for getting the logged in user name for an arbitrary desktop (via either it's respective HDESK or HNWD handle or even the desktop's stations HWINSTA handle)? thanks in advance.

推荐答案

的问题是,桌面与用户的所有关联。尝试使用PSEXEC运行SYSTEM帐户下的记事本。它的运行你的窗口站上,在桌面上。否则,你将无法看到它。

The problem is that desktops aren't associated with users at all. Try using psexec to run Notepad under the SYSTEM account. It's running on your window station, on your desktop. Otherwise, you wouldn't be able to see it.

但是,如果你想获得与窗口站相关联的会话,那么是有可能。您需要调用<一个href=\"http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/Type%20independed/NtQueryObject.html\"相对=nofollow> NtQueryObject ,提供ObjectNameInformation来获取对象的名称。例如,这里是我得到: \\会话\\ 1 \\ WINDOWS \\ WindowStations \\ WinSta0 。有你的会话ID。

But if you want to get the session associated with the window station, then yes it's possible. You need to call NtQueryObject with ObjectNameInformation to get the name of the object. For example, here's what I get: \Sessions\1\Windows\WindowStations\WinSta0. There's your session ID.

这篇关于获取登录与桌面相关联的Windows用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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