Which Windows NT (Server or Workstation) Is Running?

Last reviewed: June 24, 1997
Article ID: Q124305

The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.51 and 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;
   }
 

	
	


Keywords : BseMisc BseRegistry kbcode kbprg kbcode kbhowto kbprg
Version : 3.51 4.0
Platform : NT WINDOWS
Issue type : kbhowto
Resolution Type : kbcode


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.