WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WMI
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Determining If a Machine is a Domain Controller


Question:

This sounds like a question I should already know the answer to, but does anyone know how to tell if the machine a user is logged into is a DC and to which domain the DC belongs?

I'm trying to write an install script that has to apply file security to a file. The groups involved are either in an AD domain if the server is a DC, or in the server's local SAM database if it's a member server. The user running the script may be logged in with an account from a trusted domain, so I need to know the server status, regardless of the user running the script.

Anyone have any suggestions on how to get at the domain of server and determine if it's a DC?

Answer:

There are several ways to find a computers role.

Here is the WMI approach.

strComputer = "."
objWMIService = GetObject(StrCat("winmgmts:{impersonationLevel=impersonate}!\\",strComputer,"\root\cimv2"))
colComputers  = objWMIService.ExecQuery("Select DomainRole from Win32_ComputerSystem")
ForEach objComputer In colComputers
   Select objComputer.DomainRole
      Case 0
      strComputerRole = "Standalone Workstation"
      Break
      Case 1
      strComputerRole = "Member Workstation"
      Break
      Case 2
      strComputerRole = "Standalone Server"
      Break
      Case 3
      strComputerRole = "Member Server"
      Break
      Case 4
      strComputerRole = "Backup Domain Controller"
      Break
      Case 5
      strComputerRole = "Primary Domain Controller"
      Break
   EndSelect
   Message("",strComputerRole)
Next

objComputer   = 0
colComputers  = 0
objWMIService = 0
Exit

Or you can look at the following registry keys:

To get DC you can use:

ret = RegQueryValue(@REGMACHINE,"SOFTWARE\Microsoft\MSDTC\Security[DomainControllerState]")
If ret
  Message("Result","Machine is a Domain Controller")
Else
  Message("Result","Machine is NOT a Domain Controller")
EndIf
For Domain Name you can use
domain = RegQueryValue(@REGMACHINE,"Software\Microsoft\Windows NT\CV\WinLogon[DefaultDomainName]")
Message("Domain Name",domain)

Article ID:   W17315
File Created: 2007:07:03:14:29:28
Last Updated: 2007:07:03:14:29:28