当前位置: 首页 > 编程语言 > C#

如何使用objectGUID获取DirectoryEntry?分享

时间:2023-04-10 12:15:57 C#

如何使用objectGUID获取DirectoryEntry?我知道,我们可以这样得到一个DirectoryEntry:stringconPath="LDAP://10.0.0.6/DC=wds,DC=gaga,DC=com";stringconUser="管理员";stringconPwd="Iampassword";DirectoryEntryde=newDirectoryEntry(conPath,conUser,conPwd,AuthenticationTypes.Secure);我们可以像这样更改用户的密码:DirectorySearcherdeSearch=newDirectorySearcher();deSearch.SearchRoot=de;deSearch.Filter=String.Format("sAMAccountName={0}","xumai");SearchResultCollection结果=deSearch.FindAll();foreach(结果中的SearchResultobjResult){DirectoryEntryobj=objResult.GetDirectoryEntry();obj.Invoke("setPassword",newobject[]{"Welcome99"});obj.CommitChanges();如果使用字符串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))";希望这对你有帮助谢谢有几种方法可以在不更改代码的情况下绑定到Active-Directory。还有两种方法:第一种使用GUID绑定到对象:stringconPath="LDAP://10.0.0.6/";第二个使用SID绑定到对象:stringconPath="LDAP://10.0.0.6/";使用安全主体,您可以这样做:UserPrincipaluser=UserPrincipal.FindByIdentity(adPrincipalContext,IdentityType.DistinguishedName,"CN=User1Acct,OU=TechWriters,DC=wds,DC=gaga,DC=com");或UserPrincipaluser=UserPrincipal.FindByIdentity(adPrincipalContext,IdentityType.Guid,"0b118130-2a6f-48d0-9b66-c12a0c71d892");如果.NET3.5是一个选项,您应该开始使用System.DirectoryServices.AccountManagement。这是一个全新的世界。这是通过GUID查找用户的代码:使用(PrincipalContextpc=newPrincipalContext(ContextType.Domain,"LDAP://10.0.0.6","DC=wds,DC=gaga,DC=com","administrator","Iampassword")){stringtheGuid="0b118130-2a6f-48d0-9b66-c12a0c71d892";UserPrincipalup=UserPrincipal.FindByIdentity(pc,IdentityType.Guid,theGuid);}同一模板很容易适用于其他对象类型。以上就是C#学习教程:HowtouseobjectGUIDtogetDirectoryEntry?如果所有分享的内容对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: