Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Detecting NT Workstation vs. Server

Posted on 1999-01-04
5
Medium Priority
?
337 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 800 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

926 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