I have a problem, How can I check the windows version from the registry in c#?
(Windows xp to windows 8.1)
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With