How to tell if the OS is Windows XP or higher?

AngryHacker picture AngryHacker · Apr 28, 2010 · Viewed 16.5k times · Source

I am trying to play with the Environment.OSVersion.Version object and can't really tell what version would indicate that the OS is Windows XP or higher (e.g. I want to exclude Windows 2000, ME or previous versions).

Answer

ParmesanCodice picture ParmesanCodice · Apr 28, 2010

Use the System.OperatingSystem object, then filter on the Major & Minor version numbers.

I've used these functions in the past:

static bool IsWinXPOrHigher()
{
    OperatingSystem OS = Environment.OSVersion;
    return (OS.Platform == PlatformID.Win32NT) && ((OS.Version.Major > 5) || ((OS.Version.Major == 5) && (OS.Version.Minor >= 1)));
}

static bool IsWinVistaOrHigher()
{
    OperatingSystem OS = Environment.OSVersion;
    return (OS.Platform == PlatformID.Win32NT) && (OS.Version.Major >= 6);
}