Click here to Skip to main content
15,868,292 members
Articles / Operating Systems / Windows
Article

Determining the specific edition of Windows for now and in the future

Rate me:
Please Sign up or sign in to vote.
3.14/5 (4 votes)
2 Jan 20072 min read 33.8K   169   15   2
This article describes how to determine the specific edition of Windows that your application is running on even if that version does not yet exist.

Introduction

While determining the version number of the copy of Windows that a .NET application is running on has been relatively easy with Environment.OSVersion. Knowing exactly which version of Windows it is and what edition it is (Home, Pro, Tablet, Media Center, N, etc) has been a bit more difficult and an ever changing edition set assumes one is actually detectable.

With the introduction of Windows Vista and it's 9 different editions, it seemed as if being able to easily tell the difference between them was going to be even more difficult... not so.

At last Microsoft has provided a simple API for determining which Windows edition (a.k.a. SKU or product type) is being run within a general family as well as provides a way for you to be aware of future versions of Windows without having to change your application down the line.

I present GetProductInfo:

C#
[DllImport("Kernel32.dll")]
internal static extern bool GetProductInfo(
    int osMajorVersion,
    int osMinorVersion,
    int spMajorVersion,
    int spMinorVersion,
    out ProductType edition);

Usage

In order to determine which edition of Windows a PC is running, one need only call GetProductInfo and capture the output value of the last parameter if the method call is successful:

C#
ProductType edition = ProductType.Undefined;

if (GetProductInfo(6, 0, 0, 0, out edition))
{
    Console.WriteLine("Edition: " + edition);
}

If we want to be less specific than just a specific version (i.e. Ultimate or not), we can also use a quick switch block to see if the version is of a specific type:

C#
switch (edition)
{
    case ProductType.HomeBasic:
    case ProductType.HomeBasicN:
    case ProductType.HomePremium:
    case ProductType.HomeServer:
    //Is home edition
    break;
}

The Future

But how does this make your code able to deal with future unannounced or unknown versions? Why are we arbitrarily specifying a version number in our API call?

The enum that GetProductInfo() uses today is tied to the 6.0.0.0 version of Windows (Vista) and in later versions will likely be updated along with a new version number while still retaining awareness of the old one(s).

This means that when your application built today against Vista is run on a future system that uses a different ProductType value, the API will recognize that your app is only aware of ProductTypes that existed in the 6.0.0.0 version of the enum, and return a value of that type instead of returning an unknown value.

Take the switch statement from above... what happens if in the future Microsoft releases Windows Home Edition for Kids and that has a ProductType value of HomeKids... rather than returning an unknown value, you might receive HomeBasic back instead because you have already specified the version of the enum you are aware of.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralGet Description Pin
shawkins25-Jan-07 12:25
shawkins25-Jan-07 12:25 
This is nice if I want to compare the version to make sure that I my application will work with a specific version. However, if I am trying to simply get the name of the specific edition of Windows to pass back to me for support purposes, how do I do that? Is there an api that will return a complete description of the current OS?
AnswerRe: Get Description Pin
Isaak Newton16-Nov-08 7:55
Isaak Newton16-Nov-08 7:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.