How to add a manager for a user in Active directory using Infopath web forms
One creating a new user in Active Directory (AD), you might want to add or assign a manager to the user. Below is the function to add a manager to the user using infopath web forms
Public Sub AddManager(ByVal dEntry As DirectoryEntry, ByVal ManagerAccount As String, ByVal loginname As String)
Try
Dim ManagerSAM As String = ManagerAccount
Dim ManagerSearcher As New DirectorySearcher()
ManagerSearcher.PageSize = 10
ManagerSearcher.Filter = “(&(objectCategory=user) (samAccountName=” & ManagerAccount & “))”
ManagerSearcher.PropertiesToLoad.Add(“DistinguishedName”)
ManagerSearcher.SearchScope = SearchScope.Subtree
Dim managerResult As SearchResult
Dim ManagerResultCol As SearchResultCollection = ManagerSearcher.FindAll()
If ManagerResultCol Is Nothing Then
Else
managerResult = ManagerResultCol(0)
Dim ManagerName As String = String.Format(managerResult.Properties(“DistinguishedName”)(0))
SetADProperty(dEntry, “Manager”, ManagerName)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, “Active Directory Error”, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End Try
End Sub
Thanks Tosh – Great post. But this form then becomes admin approved form?