I need to determine the type of server that my software will be running on, I can determine if it is NT, 2000 or XP. But now I need to determine if it is a Domain Controller. Any help in how to determine this would be great.
Printable View
I need to determine the type of server that my software will be running on, I can determine if it is NT, 2000 or XP. But now I need to determine if it is a Domain Controller. Any help in how to determine this would be great.
Check out the NetServerGetInfo() function, there should be flags in there that will give you the info you need.
From MSDN:
Code:#ifndef UNICODE
#define UNICODE
#endif
#include <stdio.h>
#include <windows.h>
#include <lm.h>
int wmain(int argc, wchar_t *argv[])
{
DWORD dwLevel = 101;
LPSERVER_INFO_101 pBuf = NULL;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL;
if (argc > 2)
{
fwprintf(stderr, L"Usage: %s [\\\\ServerName]\n", argv[0]);
exit(1);
}
// The server is not the default local computer.
//
if (argc == 2)
pszServerName = argv[1];
//
// Call the NetServerGetInfo function, specifying level 101.
//
nStatus = NetServerGetInfo(pszServerName,
dwLevel,
(LPBYTE *)&pBuf);
//
// If the call succeeds,
//
if (nStatus == NERR_Success)
{
//
// Check for the type of server.
//
if ((pBuf->sv101_type & SV_TYPE_DOMAIN_CTRL) ||
(pBuf->sv101_type & SV_TYPE_DOMAIN_BAKCTRL) ||
(pBuf->sv101_type & SV_TYPE_SERVER_NT))
printf("This is a server\n");
else
printf("This is a workstation\n");
}
//
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
return 0;
}
thanks, I found a better way using OSVERSIONINFOEX. But thank you for your help