I have used VB6 quite a bit but this is my first project using .NET.
I found an example that allows me to search through our Active Directory Server to find a user by what it calls Alias. Since I cannot find that field in the user property, I am assuming it means the User Logon Name. No matter, I am not getting that far anyway. In the example from the help file (which I’ll paste at the end), it doesn’t give you how to actually use the code. I created a command button on a form to run it and hardcoded my user name in AD in the code of the event. I used the following code in the click event of the command button:
SearchMachine.Main(“mshea”)
This will return an error: C:DatabaseNETLDAP.NETForm1.vb(63): Value of type ‘String’ cannot be converted to ‘1-dimensional array of String’.
The class is as follows:
Public Overloads Shared Function Main(ByVal args As String()) As Integer
args = Environment.GetCommandLineArgs()
If args.Length < 2 Then
PrintUsage(args(0))
Return 0
End If
Dim alias1 As String = args(1)
Dim root As New System.DirectoryServices.DirectoryEntry("LDAP://121.21.121.121/CN=Our Users,DC=AD,DC=CHOC,DC=ORG")
Dim searcher As New System.DirectoryServices.DirectorySearcher(root)
searcher.Filter = "(mailNickname=" + alias1 + ")"
searcher.PropertiesToLoad.Add("cn")
searcher.PropertiesToLoad.Add("title")
searcher.PropertiesToLoad.Add("department")
searcher.PropertiesToLoad.Add("physicalDeliveryOfficeName")
searcher.PropertiesToLoad.Add("telephoneNumber")
Dim results As SearchResultCollection
results = searcher.FindAll()
Dim result As SearchResult
For Each result In results
Console.WriteLine(result.Properties("cn")(0))
Console.WriteLine(result.Properties("title")(0))
Console.WriteLine(result.Properties("department")(0))
Console.WriteLine(result.Properties("physicalDeliveryOfficeName")(0))
Console.WriteLine(result.Properties("telephoneNumber")(0))
Next result
End Function
Public Shared Sub PrintUsage(ByVal appName As String)
Console.WriteLine("Usage: " + appName + "”)
End Sub
End Class