如何使用的objectGUID得到一个DirectoryEntry?如何使用、objectGUID、DirectoryEntry

2023-09-08 12:37:04 作者:那惨淡苍白的回忆

我知道,我们可以得到这样一个DirectoryEntry:

I know ,we can get a DirectoryEntry like this:

string conPath = "LDAP://10.0.0.6/DC=wds,DC=gaga,DC=com";
string conUser = "administrator";
string conPwd = "Iampassword";
DirectoryEntry de = new DirectoryEntry(conPath, conUser, conPwd, AuthenticationTypes.Secure);

和我们可以改变用户的口令是这样的:

and we can change a user's password like this:

DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = de;
deSearch.Filter = String.Format("sAMAccountName={0}", "xumai");
SearchResultCollection results = deSearch.FindAll();
foreach (SearchResult objResult in results)
{
    DirectoryEntry obj = objResult.GetDirectoryEntry();
    obj.Invoke("setPassword", new object[] { "Welcome99" });
    obj.CommitChanges();
}

如果使用

string x = obj.Guid.ToString();;

我们可以得到用户的的objectGUID0b118130-2a6f-48d0-9b66-c12a0c71d892

we can get the user's objectGUID "0b118130-2a6f-48d0-9b66-c12a0c71d892"

如何更改密码就是这个基地的objectGUID?

how can i change it is password base this objectGUID ?

如何搜索用户群这个的objectGUID形式的LDAP://10.0.0.6/DC=wds,DC=gaga,DC=com?

how to search the user base this objectGUID form "LDAP://10.0.0.6/DC=wds,DC=gaga,DC=com"?

有没有办法筛选吗?等strFilter的=(及(的objectGUID = 0b118130-2a6f-48d0-9b66-c12a0c71d892));

is there any way filter it ? etc strFilter = "(&(objectGUID=0b118130-2a6f-48d0-9b66-c12a0c71d892))";

希望对你有所帮助。

感谢。

推荐答案

在不改变你code你得的多种方式绑定到活动目录。这里有两个其他方式:

Without changing you code you've got multiple way to bind to Active-Directory. Here are two others ways :

第一个使用GUID绑定对象:

string conPath = "LDAP://10.0.0.6/<GUID=0b118130-2a6f-48d0-9b66-c12a0c71d892>";

第二个使用SID绑定到对象:

string conPath = "LDAP://10.0.0.6/<SID=S-X-X-XX-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXX-XXX>"; 

使用安全主体你可以做这样的:

UserPrincipal user = UserPrincipal.FindByIdentity(adPrincipalContext, IdentityType.DistinguishedName,"CN=User1Acct,OU=TechWriters,DC=wds,DC=gaga,DC=com");

UserPrincipal user = UserPrincipal.FindByIdentity(adPrincipalContext, IdentityType.Guid,"0b118130-2a6f-48d0-9b66-c12a0c71d892");