.Net Tips – Checking the current OS version

You can find out some useful information about the OS your application is running in by using the Environment.OSVersion property:

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);


You can also easily check for the minimum OS version:

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