Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2009-02-13
Medium Priority
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.
Question by:AndyAinscow

Expert Comment

ID: 23631332
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

LVL 45

Author Comment

ID: 23631478
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.
LVL 86

Accepted Solution

jkr earned 1000 total points
ID: 23633384
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 );
			printf( "%s is a member of domain %.*S\n",
				argv[1], pd->Name.Length, pd->Name.Buffer );

Open in new window

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 12

Assisted Solution

Gideon7 earned 1000 total points
ID: 23634350
Check the registry key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\NTDS\Parameters, value "DSA Working Directory", is non-empty.
LVL 45

Author Comment

ID: 23667962
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.
LVL 12

Expert Comment

ID: 23668069
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
LVL 45

Author Closing Comment

ID: 31546501
Thanks, Registry lookup appears to be reliable, also Vista UAC also requires some code changes for it to work but certainly doable.

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Server 2003 introduced persistent Volume Shadow Copies and made 2003 a must-do upgrade.  Since then, it's been a must-implement feature for all servers doing any kind of file sharing.
Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question