通过LDAP VB.Net更新用户属性 [英] Update User Properties via LDAP VB.Net

查看:107
本文介绍了通过LDAP VB.Net更新用户属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我正在尝试更新登录用户的AD属性,但是由于某种原因,它没有更新.下面是Button子例程.任何想法都很棒!在本地运行时没有出现任何错误,但是没有任何反应,也没有更新.


受保护的子update_user_information(ByVal发送者作为对象,ByVal e作为System.EventArgs)处理Button1.单击

Dim sPath As String ="LDAP://"
Dim dirEntry作为新DirectoryEntry(sPath,"Admin",密码")
Dim dirSearcher作为DirectorySearcher =新DirectorySearcher(dirEntry)

dirSearcher.Filter = [String] .Format((SAMAccountName = {0 }),System.Environment.UserName)
dirSearcher.SearchScope = SearchScope.Subtree
dirSearcher.PropertiesToLoad.Add(" cn)
dirSearcher.PropertiesToLoad.Add(" company)
dirSearcher .PropertiesToLoad.Add("description")
dirSearcher.PropertiesToLoad.Add("homePhone")dirSearcher.PropertiesToLoad.Add("department")
dirSearcher.PropertiesToLoad.Add("mail")
dirSearcher.PropertiesToLoad.Add("telephoneNumber")
将searchResults作为SearchResult = dirSearcher.FindOne()
将dirEntryResults作为新DirectoryEntry(searchResults.Path)

如果dep.Text是<> ; "---"然后
dirEntryResults.Properties(部门").Add(dep.Text)
如果在

"If textbox_Office_Phone.Text<>中结束"---"然后
''dirEntryResults.Properties("telephoneNumber").Add(textbox_Office_Phone.Text)
''结束如果

dirEntryResults.CommitChanges()

dirEntryResults.Close()
结束子

Hello!

I am trying to update the logged on user''s AD properties, but for some reason it is not updating. below is the Button sub routine. Any ideas would be great!! I am not getting any errors when I run it local, but nothing happens, no update.


Protected Sub update_user_information(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim sPath As String = "LDAP://"
Dim dirEntry As New DirectoryEntry(sPath, "Admin", "Password")
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)

dirSearcher.Filter = [String].Format("(SAMAccountName={0})", System.Environment.UserName)
dirSearcher.SearchScope = SearchScope.Subtree
dirSearcher.PropertiesToLoad.Add("cn")
dirSearcher.PropertiesToLoad.Add("company")
dirSearcher.PropertiesToLoad.Add("description")
dirSearcher.PropertiesToLoad.Add("homePhone")
dirSearcher.PropertiesToLoad.Add("department")
dirSearcher.PropertiesToLoad.Add("mail")
dirSearcher.PropertiesToLoad.Add("telephoneNumber")
Dim searchResults As SearchResult = dirSearcher.FindOne()
Dim dirEntryResults As New DirectoryEntry(searchResults.Path)

If dep.Text <> "---" Then
dirEntryResults.Properties("department").Add(dep.Text)
End If

''If textbox_Office_Phone.Text <> "---" Then
''dirEntryResults.Properties("telephoneNumber").Add(textbox_Office_Phone.Text)
''End If

dirEntryResults.CommitChanges()

dirEntryResults.Close()
End Sub

推荐答案

写道:​​

如果dep.Text<> "---"然后

If dep.Text <> "---" Then



您确定这是真的吗?



Are you sure that this is ever evaluating to true?


这篇关于通过LDAP VB.Net更新用户属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆