Detect if a server is a Domain Controller

  • Thread starter Thread starter Reader
  • Start date Start date
R

Reader

Avoiding the subject to rant about how I cannot find a way to use native
..NET to retreive information about Windows..... I have found that what I
used to think worked does not appear to work anymore... I have some code
that should allow me to return if a server is a domain controller or not.
The questions that I have are what is the correct way to access if a server
is a domain controller in .NET? Or why is my code not working.



static public bool isDomainController
{
get
{
OSVERSIONINFOEX osex = new OSVERSIONINFOEX();
osex.dwOSVersionInfoSize = Marshal.SizeOf( osex );

if ( osex.wProductType == VER_NT_DOMAIN_CONTROLLER )
{
return true;
}
else
return false;
}
}

[StructLayout(LayoutKind.Sequential)]

public struct OSVERSIONINFOEX

{

public int dwOSVersionInfoSize;

public int dwMajorVersion;

public int dwMinorVersion;

public int dwBuildNumber;

public int dwPlatformId;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)]

public string szCSDVersion;

public short wServicePackMajor;

public short wServicePackMinor;

public short wSuiteMask;

public byte wProductType;

public byte wReserved;

}



[DllImport("kernel32.dll")]

public static extern short GetVersionEx(ref OSVERSIONINFOEX lpVersionInfo);





const int UF_SCRIPT = 0x0001;

const int UF_ACCOUNTDISABLE = 0x0002;

const int UF_HOMEDIR_REQUIRED = 0x0008;

const int UF_LOCKOUT = 0x0010;

const int UF_PASSWD_NOTREQD = 0x0020;

const int UF_PASSWD_CANT_CHANGE = 0x0040;

const int UF_TEMP_DUPLICATE_ACCOUNT = 0x0100;

const int UF_NORMAL_ACCOUNT = 0x0200;

const int ADS_UF_DONT_EXPIRE_PASSWD = 0x10000;

private const byte VER_NT_WORKSTATION = 0x1;

private const byte VER_NT_DOMAIN_CONTROLLER = 0x2;

private const byte VER_NT_SERVER = 0x3;
 
I think i found my error.. i forgot my call ...

GetVersionEx(ref osex);



i think it is time to step away from the computer and have dinner......
 
Back
Top