We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Is the current 'PC' configured as a domain server?

Medium Priority
292 Views
Last Modified: 2012-05-06
Is there a way I can tell PROGRAMATICALLY that the current operating system is configured as a domain server ?  If yes then how?


I am coding two utilities for configuring some software, one performs actions specific to the server, the other specific to the client PC's.  It would be very nice that the software can suggest which set of actions to perform when started.
Comment
Watch Question

I don't know if it is possible to check it directly with C++ what i do know is that you can check if a computer is a DC with te tool 'DSQuery' http://technet.microsoft.com/en-us/library/cc732952.aspx.

I found the following example using a batch file:

The syntax for using ISGC.bat is:
call ISGC ServerName GCVar

Where ServerName is the NetBIOS name of the domain controller, and GCVar is a call directed environment variable that will be set to:

X    if the server is not found, or is not a domain controller.
Y    if the domain controller is a Global Catalog server.
N    if the domain controller is NOT a Global Catalog server.

ISGC.bat contains:

@echo off
if {%2}=={} @echo Syntax: ISGC ServerName GCVar&exit /b 1
:: Initialize GCVar to X (NOT Found or NOT a DC).
set %2=X
for /f "Tokens=*" %%s in ('dsquery server -domain "%USERDNSDOMAIN%" -name %1') do (
:: Server is found.
 set %2=N
 for /f "Tokens=*" %%g in ('dsquery server -domain "%USERDNSDOMAIN%" -name %1 -isgc') do (
:: Server is a Global Catalog Server.
  set %2=Y
 )
)

Open in new window

AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Author

Commented:
From the link.

Dsquery is a command-line tool that is built into Windows Server 2008


I can't rely on everyone having that as minimum operating system.

Thanks anyway.
CERTIFIED EXPERT
Top Expert 2012
Commented:
Try to ask LSA, see http://win32.mvps.org/lsa/lsa_lqip2.cpp - the part of interest is
		if ( EqualSid( ad->DomainSid, pd->Sid ) )
			printf( "%s is a domain controller for domain %.*S\n",
				argv[1], pd->Name.Length, pd->Name.Buffer );
		else
			printf( "%s is a member of domain %.*S\n",
				argv[1], pd->Name.Length, pd->Name.Buffer );

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Commented:
Check the registry key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\NTDS\Parameters, value "DSA Working Directory", is non-empty.
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Author

Commented:
Thanks for the suggestions.
I have tried both suggestions as far as I can here.  I have also asked someone elsewhere on another system to do a quick check for me with a different system setup.  Hopefully I will get the results back and clean this question up shortly.

Commented:
jkr: That test does not work on Windows Server 2008.
See http://msdn.microsoft.com/en-us/library/aa378313.aspx#ctl00_rs1_WikiContent_ctl00_ctl02
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Author

Commented:
Thanks, Registry lookup appears to be reliable, also Vista UAC also requires some code changes for it to work but certainly doable.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.