Solved

Detecting NT Workstation vs. Server

Posted on 1999-01-04
5
320 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
  • 4
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the answer, that was exactly what I was looking for.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now