如何使用objectGUID获取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 的密码?
如何搜索用户群这个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需更改代码,您就可以多种方式绑定到 Active-Directory。这里还有另外两种方法:
第一种 使用 GUID绑定到一个对象:
第二个使用 SID 绑定到对象:
使用安全主体你可以这样做:
或者
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:
The second one use SID to bind to an object:
Using security Principals you can do it like that :
or
如果可以选择 .NET 3.5,则应开始使用 System.DirectoryServices.AccountManagement。这是一个全新的世界。下面是通过 GUID 查找用户的代码:
相同的模板可以轻松地适应其他对象类型。
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:The same template would be easily adapted to other object types.