Microsoft KB Archive/250324: Difference between revisions

From BetaArchive Wiki
m (Text replacement - ">" to ">")
m (Text replacement - """ to """)
 
(One intermediate revision by the same user not shown)
Line 37: Line 37:
Dim strDomain
Dim strDomain


strDomain = &quot;<Enter correct domain name here>&quot;
strDomain = "<Enter correct domain name here>"


Set oDom = GetObject(&quot;WinNT://&quot; &amp; strDomain &amp; &quot;,domain&quot;)
Set oDom = GetObject("WinNT://" & strDomain & ",domain")


oDom.Filter = Array(&quot;Computer&quot;)
oDom.Filter = Array("Computer")
For Each oComputer in oDom
For Each oComputer in oDom
     Set oUser = GetObject(&quot;WinNT://&quot; &amp; strDomain &amp; &quot;/&quot; &amp; oComputer.Name &amp; &quot;$,user&quot;)
     Set oUser = GetObject("WinNT://" & strDomain & "/" & oComputer.Name & "$,user")
     lngFlags = oUser.Get(&quot;UserFlags&quot;) And 8192
     lngFlags = oUser.Get("UserFlags") And 8192
     If lngFlags = 8192 then
     If lngFlags = 8192 then
         MsgBox oComputer.Name &amp; &quot; is either a PDC or BDC.&quot;
         MsgBox oComputer.Name & " is either a PDC or BDC."
     Else
     Else
         MsgBox oComputer.Name &amp; &quot; is either a Member server or Workstation.&quot;
         MsgBox oComputer.Name & " is either a Member server or Workstation."
     end if
     end if
Next
Next

Latest revision as of 13:51, 21 July 2020

HOWTO: Use ADSI to Determine Server Roles

Q250324



The information in this article applies to:


  • Microsoft Active Directory Service Interfaces, version 2.5





SUMMARY

This article demonstrates how to use Active Directory Services Interfaces (ADSI) to determine the role of a computer in a Microsoft Windows domain.



MORE INFORMATION

The following code uses the WinNT provider to loop through all computers in the specified domain. It checks the user flags to determine the role of each computer (either a primary domain controller [PDC]/backup domain controller [BDC], or a member server/workstation on the domain).

Dim oDom
Dim oComputer
Dim oUser
Dim lngFlags
Dim strDomain

strDomain = "<Enter correct domain name here>"

Set oDom = GetObject("WinNT://" & strDomain & ",domain")

oDom.Filter = Array("Computer")
For Each oComputer in oDom
    Set oUser = GetObject("WinNT://" & strDomain & "/" & oComputer.Name & "$,user")
    lngFlags = oUser.Get("UserFlags") And 8192
    If lngFlags = 8192 then
        MsgBox oComputer.Name & " is either a PDC or BDC."
    Else
        MsgBox oComputer.Name & " is either a Member server or Workstation."
    end if
Next

Set oUser = Nothing
Set oComputer = Nothing
Set oDom = Nothing 

Additional query words:

Keywords : kbADSI kbMsg kbVBp kbGrpDSPlatform _IK
Issue type : kbhowto
Technology : kbAudDeveloper kbADSISearch kbADSI250


Last Reviewed: February 6, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.