Click here to Skip to main content
13,250,883 members (48,261 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 2 Jan 2007

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

, 2 Jan 2007
Rate this:
Please Sign up or sign in to vote.
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.


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:

internal static extern bool GetProductInfo(
    int osMajorVersion,
    int osMinorVersion,
    int spMajorVersion,
    int spMinorVersion,
    out ProductType edition);


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:

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:

switch (edition)
    case ProductType.HomeBasic:
    case ProductType.HomeBasicN:
    case ProductType.HomePremium:
    case ProductType.HomeServer:
    //Is home edition

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 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 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.


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


About the Author

Brendan Grant
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralGet Description Pin
shawkins25-Jan-07 13:25
membershawkins25-Jan-07 13:25 
AnswerRe: Get Description Pin
Member 376225416-Nov-08 8:55
memberMember 376225416-Nov-08 8:55 
What about the GetVersionEx function?
[DllImport("kernel32.dll", EntryPoint = "GetVersionEx")]
public static extern UInt32 GetVersionEx(ref OSVERSIONINFOEX lpVersionInfo);

And then something like that:
public int OSVersion(out string OSVer)
            OSVERSIONINFOEX osvi = new OSVERSIONINFOEX();            
            uint result = GetVersionEx(ref osvi);                                  
            if (result == 0)
                OSVer = "";
                return 1;
                OSVer = "osvi.dwMajorVersion + "." + osvi.dwMinorVersion + "." + osvi.dwBuildNumber;
                return 0;

            public uint dwOSVersionInfoSize;
            public uint dwMajorVersion;
            public uint dwMinorVersion;
            public uint dwBuildNumber;
            public uint dwPlatformId;            
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
            public string szCSDVersion;            
            public Int16 wServicePackMajor;            
            public Int16 wServicePackMinor;    
            public Int16 wSuiteMask;
            public Byte wProductType;
            public Byte wReserved;

Good luck!

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 2 Jan 2007
Article Copyright 2007 by Brendan Grant
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid