3

我知道,我们可以得到这样的 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?

如何搜索用户群这个objectGUID表单“LDAP://10.0.0.6/DC=wds,DC=gaga,DC=com”?

有什么办法过滤吗?等 strFilter = "(&(objectGUID=0b118130-2a6f-48d0-9b66-c12a0c71d892))";

希望得到你的帮助

谢谢。

4

2 回答 2

8

在不更改代码的情况下,您可以通过多种方式绑定到 Active-Directory。这是另外两种方法:

第一个使用 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");
于 2011-07-12T02:37:38.867 回答
0

如果 .NET 3.5 是一个选项,您应该开始使用System.DirectoryServices.AccountManagement. 这是一个全新的世界。这是通过 GUID 查找用户的代码:

using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, 
                                                  "LDAP://10.0.0.6", 
                                                  "DC=wds,DC=gaga,DC=com", 
                                                  "administrator", 
                                                  "Iampassword"))
{
    string theGuid = "0b118130-2a6f-48d0-9b66-c12a0c71d892";
    UserPrincipal up = UserPrincipal.FindByIdentity(pc, IdentityType.Guid, theGuid);
}

相同的模板很容易适应其他对象类型。

于 2011-07-11T14:33:37.220 回答