Microsoft KB Archive/124305

{|
 * width="100%"|

INFO: Which Windows NT (Server or Workstation) Is Running?

 * }

Q124305

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), used with:
 * the operating system: Microsoft Windows NT, versions 3.51, 4.0

-

SUMMARY
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.

MORE INFORMATION
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.

Sample Code
  #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; } Additional query words:

Keywords : _IK kbnokeyword kbKernBase kbRegistry kbDSupport kbGrpDSKernBase

Issue type : kbinfo

Technology : kbAudDeveloper kbWin32sSearch kbWin32API