Active directory 如何更新“a”的值;用户证书;LDAP广告中的属性

Active directory 如何更新“a”的值;用户证书;LDAP广告中的属性,active-directory,ldap,directoryentry,directorysearcher,Active Directory,Ldap,Directoryentry,Directorysearcher,我需要更新active directory中计算机的属性(“usercert”)中保存的值 //从AD检索属性值 DirectoryEntry entry = new DirectoryEntry(LDAPPath, LDAPUser, DecryptPwd(LDAPPwd, LDAPKey)); DirectorySearcher searcher = new DirectorySearcher(entry); searcher.Filter = string.Format("(&

我需要更新active directory中计算机的属性(“usercert”)中保存的值

//从AD检索属性值

DirectoryEntry entry = new DirectoryEntry(LDAPPath, LDAPUser, DecryptPwd(LDAPPwd, LDAPKey)); 
DirectorySearcher searcher = new DirectorySearcher(entry); 
searcher.Filter = string.Format("(&(objectCategory=computer)(Name=" + MachineName + "))"); 
result = searcher.FindOne(); 
byte[] text= (byte[])result.GetDirectoryEntry().Properties["usercert"].Value;
//将新值更新为AD字符串updatedText=“new Text”

我尝试了上面所有的注释代码,但没有一个对我有效。您能帮我解决这个问题吗。

每次调用时都会创建一个新的
DirectoryEntry
对象,您可以在源代码中看到它

所以当你这样做的时候:

result.GetDirectoryEntry().CommitChanges();
它正在创建一个全新的
DirectoryEntry
对象,并在此对象上调用
CommitChanges()
。所以什么都没有改变

您只需要调用一次
GetDirectoryEntry()
,并对该对象进行更改。例如:

var resultDe=result.GetDirectoryEntry();
resultDe.Properties[“usercert”]).Value=任意值;
resultede.CommitChanges();

我已经尝试调用result.GetDirectoryEntry()一次,并使用该对象进行更新和提交,但CommitChanges()抛出“访问被拒绝”。异常。这意味着您运行此操作的帐户(
LDAPUser
)没有权限更新该帐户(或者可能只是该帐户上的该属性)。谢谢Grabriel!我要求相关团队检查必要的许可。
result.GetDirectoryEntry().CommitChanges();