Solved

Detecting NT Workstation vs. Server

Posted on 1999-01-04
5
331 Views
Last Modified: 2013-12-03
I have what should be a simple question, but I can't find it documented anywhere.  What is the CORRECT <official> way to check for NT Workstation or NT Server.  GetVersionEx() is great for figuring out Service Pack levels / Version number, but contains no information about if it is NT Workstation or Server, How does Microsoft recomend doing this?
0
Comment
Question by:jonstelly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 1418040
See the Microsoft Developer's Network Knowledge Base article Q124305. The registry entry '\hkey_local_machine\system\currentcontrolset\control\productoptions\producttype' contains one of these entries:
ProductType->System
Winnt Workstation
Servernt Server
Lanmannt Advanced Server
 

0
 
LVL 86

Expert Comment

by:jkr
ID: 1418041
Ooops, the last lines should have been a 'table', let me see whether i can improve the formatting ;-)
ProductType->System
'Winnt' means Workstation
'Servernt' means Server
'Lanmannt' means Advanced Server
 
0
 
LVL 86

Expert Comment

by:jkr
ID: 1418042
And one other thing i forgot to mention - i didn't care of uppercase or lowercase, as MS uses the above terms uppercase, but i've often seen them in lowecase, also. So i suggest a 'case insensitive' comparation ;-)
0
 
LVL 86

Expert Comment

by:jkr
ID: 1418043
Hmm, i took this as a chance to take a view at this article again, and as it is not that large, i decided to post it ;-)
Though it was intended for NT3.x, it still applies for NT4.0...

Knowledge Base
Which Windows NT (Server or Workstation) Is Running?
Article ID: Q124305
Creation Date: 27-DEC-1994
Revision Date: 26-JAN-1996
The information in this article applies to:

Microsoft Win32 Application Programming Interface (API) included with:

    - Microsoft Windows NT versions 3.1 and 3.5


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;
}

0
 

Author Comment

by:jonstelly
ID: 1418044
Thanks for the answer, that was exactly what I was looking for.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question