Check windows version from registry c#

c#

Solution

`Environment.OSVersion` as others stated is right way to go.

However, in case someone want to get it through registry, this can be used -

using (Microsoft.Win32.RegistryKey key = 
       Microsoft.Win32.Registry.LocalMachine
               .OpenSubKey(@"SOFTWARE\Microsoft\WindowsNT\CurrentVersion"))
{
    var osVersion = key.GetValue("CurrentVersion");
}

Registry for version is `HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion"`.

Also, corresponding mapping with actual OS from here -

Operating system        Version number
-----------------       --------------
Windows 8                   6.2
Windows Server 2012         6.2
Windows 7                   6.1
Windows Server 2008 R2      6.1
Windows Server 2008         6.0
Windows Vista               6.0
Windows Server 2003 R2      5.2
Windows Server 2003         5.2
Windows XP 64-Bit Edition   5.2
Windows XP                  5.1
Windows 2000                5.0

Problem

I have a problem, How can I check the windows version from the registry in c#? (Windows xp to windows 8.1)

Original source

Related problems