c# - 如何使用objectGUID得到一个DirectoryEntry?

标签 c# active-directory guid directoryservices directoryentry

我知道,我们可以这样得到一个 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/

相关文章:

c# - 将 ASP.NET 网站管理工具功能引入网页

vba - 寻找 LDAP URL?

asp.net - 带有 Asp.NET 身份的 LDAP 身份验证

c# - 单击 winform 应用程序中的按钮后,如何将焦点返回到上次使用的控件?

c# - Unity2D : Rigidbody2D. 添加对撞机时 AddForce 不起作用

c# - 如果我每次都没有取消配对我的蓝牙 LE 设备,为什么我不能发送消息? (UWP)

visual-studio - 当我在 VS 2005 中构建项目时,为什么我的项目的 GUID 之一会发生变化?

guid - 数据如何存储在磁盘上? - EFI GUID

c# - 将可为 null 的 GUID 从 C# 移植到 Java

c# - XDocument.Descendants() 与 DescendantNodes()