How can I get list of computers in a domain?

  • Thread starter Thread starter Peter Steele
  • Start date Start date
P

Peter Steele

I've found some VB code to query a domain controller to return the list of
all computers in that domain. The VB code is reasonably straightforward (see
below). How do I do the equivalent in C++? I've done a lot of searches and
haven't come up with much useful information. Any pointers would be
appreciated:

Public Function GetDomainComputers(ByVal strDomain)
Dim objIADsContainer ' ActiveDs.IADsDomain -
Dim objIADsComputer ' ActiveDs.IADsComputer
Dim vReturn ' Variant

Set objIADsContainer = GetObject("WinNT://" & strDomain)

' set the filter to retrieve only objects of class Computer
objIADsContainer.Filter = Array("Computer")

ReDim vReturn(0)
For Each objIADsComputer In objIADsContainer
If Trim(vReturn(0)) <> "" Then
ReDim Preserve vReturn(UBound(vReturn) + 1)
End If
vReturn(UBound(vReturn)) = objIADsComputer.Name
Next

GetDomainComputers = vReturn
Set objIADsComputer = Nothing
Set objIADsContainer = Nothing
End Function
 
Peter Steele said:
I've found some VB code to query a domain controller to return the list of
all computers in that domain. The VB code is reasonably straightforward (see
below). How do I do the equivalent in C++? I've done a lot of searches and
haven't come up with much useful information. Any pointers would be
appreciated:

I'm not expert at either VB or Active Directory Services but that's what I
think your snippet is using. You may want to start reading here

http://msdn.microsoft.com/library/d.../active_directory_service_interfaces_adsi.asp

and then perhaps find an Active Directory newsgroup for information on its
object model.

On the other hand if you are looking for an answer to the question in the
subject line then I'd suggest that you search the docs for NetServerEnum()
for the pre-AD way of enumerating the workstations in a domain.

Regards,
Will
 
I'd much rather use an API call than deal with Active Directory. I had
looked for something but none of my searches came up with anything. This
appears to be what I need. Thanks!
 
Two options! I'll have to check out both of these API calls and see which
suits my needs.
 
Back
Top