How to detect version of Windows OS?

Asked

Viewed 338 times

0

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 doesn’t work right.

I tried that answer here and it doesn’t work. I’m using Windows10, he returns as Windows8.

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

  • Have you read the note of the answer accepted in Soen? It seems to explain why detects as windows 8 even running the 10.

  • 1

    Important note: if your Executable Assembly manifest doesn’t explicitly state that your exe Assembly is compatible with Windows 8.1 and Windows 10.0, System.Environment.Osversion will Return Windows 8.0 version ?! which is 6.2, Instead of 6.3 and 10.0!! Source: here first comment.*

  • 1

    In any case, I leave another alternative: https://stackoverflow.com/a/31885836/5524514

  • @Article the link you sent works, in case someone changes the value in the record, iron.

  • 2

    If someone changes that key there, will close much more than your application :p

1 answer

3


I use the ManagementObjectSearcher 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);
}

Don’t forget to add the reference to Assembly System.Management.dll and put the using: using System.Management;

Upshot:

inserir a descrição da imagem aqui

ps. Mine is Windows 8.1 even =]

Documentation

  • 1

    Rovan, answer this tbm in stackoverflow "English" kkkkkkk, it really works.

  • I went to look there too, it was already answered... but I can put there yes =]... and look what I use it for a long time...and in the same way, I get information about processor, motherboard, and memory

  • Only one question, because: r = r.Replace("NT 5.1.2600", "XP"); r = r.Replace("NT 5.2.3790", "Server 2003"); ?

  • 1

    when it is windows Xp, or server 2003, the return is Microsoft Windows NT 5.1.2600, I put the replace to return: Microsoft Windows XP

Browser other questions tagged

You are not signed in. Login or sign up in order to post.