ID: Q124305
The information in this article applies to:
- Microsoft Windows NT versions 3.51 and 4.0
You can determine which variant of Windows NT (Windows NT Server or Windows NT Workstation) is running by using the technique described in this article. Then you can use this information to execute code based on which variant is running.
To find out which product is currently running, you need to determine the value of the following registry entry:
HKEY_LOCAL_MACHINE\SYSTEM\ CurrentControlSet Control\ ProductOptions
Use the following table to determine which product is running:
ProductType Product
WINNT Windows NT Workstation is running
SERVERNT Windows NT Server is running
LANMANNT Windows NT Advanced Server is running (Server as Domain
controller)
The sample code creates a WhichNTProduct() function to indicate whether
Windows NT Server or Windows NT Workstation in currently running. The
following table gives the meaning for each return value:
Return Value Meaning
RTN_SERVER Windows NT Server is running
RTN_WORKSTATION Windows NT Workstation is running
RTN_NTAS Windows NT Advanced Server is running
RTN_UNKNOWN Unknown product type was encountered
RTN_ERROR Error occurred
To get extended error information, call GetLastError(). Some error checking
is omitted, for brevity.
#define RTN_UNKNOWN 0
#define RTN_SERVER 1
#define RTN_WORKSTATION 2
#define RTN_NTAS 3
#define RTN_ERROR 13
unsigned int WhichNTProduct(void)
DWORD
WhichNTProduct(
void
)
{
#define MY_BUFSIZE 32 // arbitrary. Use dynamic allocation
HKEY hKey;
TCHAR szProductType[MY_BUFSIZE];
DWORD dwBufLen=MY_BUFSIZE;
LONG lRet;
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT("SYSTEM\\CurrentControlSet\\Control\\ProductOptions"),
0,
KEY_QUERY_VALUE,
&hKey) != ERROR_SUCCESS) return RTN_ERROR;
lRet = RegQueryValueEx(hKey,
TEXT("ProductType"),
NULL,
NULL,
(LPBYTE)szProductType,
&dwBufLen);
RegCloseKey(hKey);
if(lRet != ERROR_SUCCESS) return RTN_ERROR;
// check product options, in order of likelihood
if (lstrcmpi(TEXT("WINNT"), szProductType) == 0)
return RTN_WORKSTATION;
if(lstrcmpi(TEXT("SERVERNT"), szProductType) == 0)
return RTN_SERVER;
if(lstrcmpi(TEXT("LANMANNT"), szProductType) == 0) return RTN_NTAS;
// else return Unknown
return RTN_UNKNOWN;
}
Keywords : kbcode kbnokeyword kbKernBase kbRegistry kbGrpKernBase
Version : 3.51 4.0
Platform : NT WINDOWS
Issue type : kbhowto
Last Reviewed: May 23, 1998