.Net Tips — Checking the current OS version

You can find out some use­ful infor­ma­tion about the OS your appli­ca­tion is run­ning in by using the Environment.OSVersion prop­er­ty:

Console.WriteLine("Current OS: {0}", Environment.OSVersion.VersionString);
Console.WriteLine("Version: {0}", Environment.OSVersion..Version);
Console.WriteLine("Platform: {0}", Environment.OSVersion.Platform);
Console.WriteLine("Service Pack: {0}", Environment.OSVersion.ServicePack);

image

You can also eas­i­ly check for the min­i­mum OS ver­sion:

// minimum requirement is Windows XP or later
if (Environment.OSVersion.Version < new Version(5, 1))
{
    throw new Exception("Windows XP or later is required!");
}