Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
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?
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") EndIfFor Domain Name you can use
domain = RegQueryValue(@REGMACHINE,"Software\Microsoft\Windows NT\CV\WinLogon[DefaultDomainName]") Message("Domain Name",domain)
Article ID: W16994
File Created: 2007:07:03:14:27:32
Last Updated: 2007:07:03:14:27:32