Determine OS using Environment.OSVersion [duplicate]

The following should work. But why do you care? Is just for informational purposes in logging or are you looking for actual capabilities being present on the target platform?

if (Environment.OSVersion.Version.Major == 5)
{
    if (Environment.OSVersion.Version.Minor == 1)
    {
             // XP
    }
    else if (Environment.OSVersion.Version.Minor == 2)
    {
             // Server 2003.  XP 64-bit will also fall in here.
    }
}
else if (Environment.OSVersion.Version.Major >= 6)
{
        // Vista on up
}

Leave a Comment

tech