如何从 Active Directory DirectoryEntry (SchemaClassName="user") 对象获取 Windows 用户和域?
用户名在 sAMAccountName 属性中,但我可以在哪里查找域名?
(我不能假设一个固定的域名,因为用户来自不同的子域。)
最佳答案
这假定 results
是从 DirectorySearcher 获得的 SearchResultCollection,但您应该能够直接从 DirectoryEntry 获得 objectsid。
SearchResult result = results[0];
var propertyValues = result.Properties["objectsid"];
var objectsid = (byte[])propertyValues[0];
var sid = new SecurityIdentifier(objectsid, 0);
var account = sid.Translate(typeof(NTAccount));
account.ToString(); // This give the DOMAIN\User format for the account
关于c# - 如何从 AD DirectoryEntry 获取 DOMAIN\USER?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/941002/