How to detect the version of the Windows operating system?

-1

I want to get a value of what system you're using, like:

  • Windows 7 or

  • Windows 8 or

  • Windows 8.1 or

  • Windows 10

How can I do this in C #? I've tried System.Environment.OSVersion does not work right.

I tried this answer here and it does not work. I'm using Windows10 , it returns as Windows8 .

I have already tried the "English" stackoverflow, none of them did not work with this link .

    
asked by anonymous 08.05.2018 / 02:05

1 answer

2

I use ManagementObjectSearcher of namespace System.Management

Example:

string r = "";
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem"))
{
    ManagementObjectCollection information = searcher.Get();
    if (information != null)
    {
        foreach (ManagementObject obj in information)
        {
            r = obj["Caption"].ToString() + " - " + obj["OSArchitecture"].ToString();
        }
    }
    r = r.Replace("NT 5.1.2600", "XP");
    r = r.Replace("NT 5.2.3790", "Server 2003");
    MessageBox.Show(r);
}
  

Do not forget to add the reference to Assembly System.Management.dll   and put the using: using System.Management;

Result:

ps.MyisWindows8.1same=]

Documentation

    
08.05.2018 / 02:55