我知道,我们可以这样得到一个 DirectoryEntry:
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);
我们可以像这样更改用户的密码:
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();;
我们可以得到用户的objectGUID "0b118130-2a6f-48d0-9b66-c12a0c71d892"
我如何更改它是基于此 objectGUID 的密码?
如何从“LDAP://10.0.0.6/DC=wds,DC=gaga,DC=com”中搜索这个对象GUID形式的用户群?
有什么办法过滤吗?等等 strFilter = "(&(objectGUID=0b118130-2a6f-48d0-9b66-c12a0c71d892))";
希望得到您的帮助
谢谢。
最佳答案
在不更改代码的情况下,您得到了 multiple way to bind to Active-Directory .这里有另外两种方式:
第一个use GUID to bind to an object :
string conPath = "LDAP://10.0.0.6/<GUID=0b118130-2a6f-48d0-9b66-c12a0c71d892>";
第二个use SID to bind to an object :
string conPath = "LDAP://10.0.0.6/<SID=S-X-X-XX-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXX-XXX>";
使用 security Principals你可以这样做:
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");
关于c# - 如何使用objectGUID得到一个DirectoryEntry?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6651586/