Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check windows version from registry c# [closed]

Tags:

c#

I have a problem, How can I check the windows version from the registry in c#?

(Windows xp to windows 8.1)

like image 590
user2690381 Avatar asked Dec 12 '22 12:12

user2690381


2 Answers

Environment.OSVersion can give you that!

Read the MSDN documentation for Environment class to see all of the other things you can get from this class.

like image 133
Ehsan Avatar answered Dec 24 '22 02:12

Ehsan


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
like image 30
Rohit Vats Avatar answered Dec 24 '22 03:12

Rohit Vats