Which Windows NT (Server or Workstation) Is Running?Last reviewed: June 24, 1997Article ID: Q124305 |
The information in this article applies to:
SUMMARYYou 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 INFORMATIONTo 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 occurredTo 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |