我想将SID的System.Byte[]类型转换为字符串。
我的代码:
我的代码:
string path = "LDAP://DC=abc,DC=contoso,DC=com";
DirectoryEntry entry = new DirectoryEntry(path);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(&(objectClass=user)(samaccountname=user1))";
results = mySearcher.FindAll();
foreach (SearchResult searchResult in results)
{
Console.WriteLine(searchResult.Properties["ObjectSID"][0].ToString());
}
我尝试了这个方法,但它获取的值来自我当前登录的域名,而我需要获取给定域名的值。
System.Security.Principal.NTAccount(user1)
.Translate([System.Security.Principal.SecurityIdentifier]).value