简体   繁体   English

当 AD 不可用时,如何从用户名中获取用户的 SID?

[英]How can I get the SID of a user having from his/her username when the AD is not available?

I'm trying to get a user SID by using the following function:我正在尝试使用以下 function 获取用户 SID:

return new NTAccount(username).Translate(typeof(SecurityIdentifier)).ToString();

Although this function works almost in all cases, when the machine in which this function runs is isolated from the Active Directory this usually gives me a system exception with the following associated message:尽管此 function 几乎在所有情况下都有效,但当运行此 function 的计算机与 Active Directory 隔离时,这通常会给我一个系统异常,并显示以下相关消息:

The trust relationship between this workstation and the primary domain failed. 

Is there a way to bypass this and permit the NTAccount function to work only by looking inside the locally available users?有没有办法绕过这个并允许 NTAccount function 仅通过查看本地可用用户来工作?

Doing some testing, when launching a command with the User associated with the input of the NTAccount, and after having launched the command successfully, the Translate command starts working without it being dependent on the AD.做一些测试,当使用与 NTAccount 的输入相关联的用户启动命令时,并且在成功启动命令后,Translate 命令开始工作,而不依赖于 AD。

I am trying to use that function in a custom credential provider in order to enable a custom 2FA and I need the SID (an unique identifier) to be used for user identification in my backend service.我正在尝试在自定义凭据提供程序中使用该 function 以启用自定义 2FA,并且我需要将 SID(唯一标识符)用于后端服务中的用户标识。

Have a look at registry path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList .查看注册表路径HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

There are SID s of users (including system Accounts too).有用户的SID (也包括系统帐户)。

Then look at HKEY_USERS\<SID>\Volatile Environment path.然后查看HKEY_USERS\<SID>\Volatile Environment路径。
Values USERDOMAIN and USERNAME wait for you.USERDOMAINUSERNAME等着你。

Found here - Getting the Username from the HKEY_USERS values在这里找到 -从 HKEY_USERS 值中获取用户名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当他/她的帐户被锁定时,向用户发送短信通知消息,我怎样才能在C#中执行此操作 - Send sms notify message to user when his/her account locked, how can i do that in C# 如何在其他用户更改其用户名时强制注销用户? - How to force logout user when his/her username is changed by another user? 如何从服务器获取用户的SID? - How do I get the user's SID from the server? 如何通过ldap中的域名获取用户的用户名和SID - How to get username and SID for user by a domain name in ldap 如何从 AD DirectoryEntry 获取 DOMAIN\\USER? - How can I get DOMAIN\USER from an AD DirectoryEntry? 如何检查用户是否正确输入了用户名和密码? - How can I check if a user has written his username and password correctly? 检查用户是否使用GuildMemberUpdated更改了其昵称 - Check if a user changed his/her nick with GuildMemberUpdated 每当用户更新gridview时,如何获取用户名会话并将其用户名更新到数据库? - how to get session of username and update his username to the database whenever the user updates the gridview? 给定用户的SID,如何获取其userPrincipalName? - Given a user's SID, how do I get their userPrincipalName? 将SID或用户名存储在AD帐户的数据库中吗? - Store SID or Username in database for AD Accounts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM