Hi All
I am very new to VB.net, I want to learn about getting information from Active Directory, I use to do this via ADSI.
I have seen the following code, that should List all the computers in active directory:
'ActiveDirectorySearch1
'Displays all computer names in an Active Directory
'Written 08/26/02 - John O'Donnell -
[email protected]
Imports System
Imports System.DirectoryServices
Namespace ActiveDirectorySearch1
Class Class1
Shared Sub Main(ByVal args() As String)
'Note : microsoft is the name of my domain for testing purposes.
Dim enTry As DirectoryEnTry = New DirectoryEnTry("LDAP://microsoft")
Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)
mySearcher.Filter = ("(objectClass=computer)")
Console.WriteLine("Listing of computers in the Active Directory")
Console.WriteLine("======================")
Dim resEnt As SearchResult
For Each resEnt In mySearcher.FindAll()
Console.WriteLine(resEnt.GetDirectoryEnTry().Name.ToString())
Next
Console.WriteLine("=========== End of Listing =============")
End Sub
End Class
End Namespace
Not a problem, add a new class, and paste the code in, drag "DirectoryEntry" & "DirectorySeacher" onto the form, and this adds System.DirectoryServices to the References.
But what do I do now, If I add a button, and add "Main()" to the click, I get the following error:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.windows.forms.dll
Additional information: It is invalid to start a second message loop on a single thread. Use Application.RunDialog or Form.ShowDialog instead.
Any help would be good.
Richard