how I retreive computernameof clients in activedirectory ?

i wrote these :
Dim management_object As ManagementObject
        Dim m_local_domain_name As String
        Dim m_local_computer_name As String
        For Each management_object In queryCollection
            m_local_domain_name = management_object("Domain")
            m_local_computer_name = management_object("Name")
        Next management_object

        Dim a As DirectoryEntry = GetComputersInfoCollection("")
        Dim mySearcher As System.DirectoryServices.DirectorySearcher = _
        New System.DirectoryServices.DirectorySearcher(a)
        mySearcher.Filter = ("(objectClass=computer)")
        Dim resEnt As System.DirectoryServices.SearchResult
        For Each resEnt In mySearcher.FindAll()
                TextBox20.Text = TextBox20.text + (":Processing:" & Mid(resEnt.GetDirectoryEntry).Name.ToString(), 4))

            Catch ex As Exception
                Console.WriteLine("Trying to Connect to: " & _
                  resEnt.GetDirectoryEntry().Name.ToString() & vbCrLf & ex.Message.ToString())
            End Try



Public Function GetComputersInfoCollection(ByVal domain As String) As DirectoryEntry
        Dim domainEntry As DirectoryEntry = New DirectoryEntry("WinNT://" + domain, "ioptc\rpi", "ali ranji 321", AuthenticationTypes.Secure)
        Return domainEntry
    End Function

but when i run i get this error message:The provider does not support searching and cannot search WinNT://
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

farhadtolooieAuthor Commented:
farhadtolooieAuthor Commented:
I write
 dirEntry.Path = "LDAP://;DC=ioptc"
and I get error :
A referral was returned from the server
please help me
Here is an example of a similar function from one of my programs
Note: FQDNs don't  have semicolons (;) as in your last example (I assume that was just a typo)

    ' Get the PC list from an Active Directory domain using an LDAP query
    Public Function GetPCOUList(ByVal DomainName As String, ByVal OU_Name As String, ByVal Filter As String, ByVal Svr_Only As Boolean) As String()
        Dim entry, de As DirectoryEntry
        Dim srch As DirectorySearcher
        Dim result As SearchResult
        Dim ldap, buf, os, ans(-1) As String
        Dim sc As New StringCollection
        ldap = "LDAP://" & DomainName & "/" & OU_Name
        ' set our starting place to search
        entry = New DirectoryEntry(ldap)
        srch = New DirectoryServices.DirectorySearcher(entry)
        srch.Filter = "(ObjectCategory=computer)"
        ' A work around for a bug... this shouldn't be needed
        srch.PageSize = 1000
        ' OK, let's do it
        Filter = Filter.ToUpper
        For Each result In srch.FindAll()
            de = result.GetDirectoryEntry
            buf = de.Properties("CN").Value.ToString
            If Filter = "" OrElse Filter = buf.ToUpper Or buf.ToUpper Like Filter Then
                If Svr_Only Then
                    If de.Properties("operatingSystem").Count > 0 Then
                        os = de.Properties("operatingSystem").Value.ToString
                        If os Like "*Server*" Then
                        End If
                    End If
                End If
            End If
        If sc.Count > 0 Then
            ReDim ans(sc.Count - 1)
            sc.CopyTo(ans, 0)
        End If
        Return ans
    End Function

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
farhadtolooieAuthor Commented:
I write
dirEntry.Path = "LDAP://ioptc/OU=Users"
ioptc is our company domain and I want to get  computername of all clients,
and error occure:
operation error occured
please help me !
what I replace in OU=Users?
I'd use the full path to the domain

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.