如何使用objectGUID获取DirectoryEntry?

发布于 2024-11-19 14:30:29 字数 1079 浏览 6 评论 0原文

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

希望您的帮助,

谢谢。

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();
}

if use

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

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

how can i change it is password base this objectGUID ?

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

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

hope for your help

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光与爱终年不遇 2024-11-26 14:30:29

无需更改代码,您就可以多种方式绑定到 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");

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

The first one use GUID to bind to an object:

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

The second one use SID to bind to an object:

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

Using security Principals you can do it like that :

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

or

UserPrincipal user = UserPrincipal.FindByIdentity(adPrincipalContext, IdentityType.Guid,"0b118130-2a6f-48d0-9b66-c12a0c71d892");
月野兔 2024-11-26 14:30:29

如果可以选择 .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);
}

相同的模板可以轻松地适应其他对象类型。

If .NET 3.5 is an option, you should start using System.DirectoryServices.AccountManagement. It is a whole new world. Here's is the code to find a user by the 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);
}

The same template would be easily adapted to other object types.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文