Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current version OS in Windows 10 in C#

I Use C#. I try to get the current version of the OS:

OperatingSystem os = Environment.OSVersion;
Version ver = os.Version;

I get on the Windows 10: 6.2.

But 6.2 is Windows 8 or WindowsServer 2012 (Detect Windows version in .net)

I found the following solution (How can I detect if my app is running on Windows 10).

static bool IsWindows10()
{
  var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
  string productName = (string)reg.GetValue("ProductName");
  return productName.StartsWith("Windows 10");
}

This is the best way to get the current version in C#?

like image 886
Olga Avatar asked Nov 18 '16 08:11

Olga


People also ask

How do I find my OS version using CMD?

Checking your Windows version using CMD Press [Windows] key + [R] to open the “Run” dialog box. Enter cmd and click [OK] to open Windows Command Prompt. Type systeminfo in the command line and hit [Enter] to execute the command.

How can I tell what version of Windows is on my C drive?

How to check what Windows version you have by running the winver command. Press the Windows + R keyboard keys to launch the Run window, type winver, and press Enter. Open Terminal, Command Prompt (CMD), or PowerShell, type winver, and press Enter. You can also use the search feature to open winver.

How do I find my current OS?

Click the Start or Windows button (usually in the lower-left corner of your computer screen). Right-click Computer and choose Properties from the menu. The resulting screen shows the Windows version.


1 Answers

Add application manifest to your application and add the supportedOS Id of Windows 8.1 and Windows 10 to the manifest:

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
        <application> 
            <!-- Windows 10 --> 
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
            <!-- Windows 8.1 -->
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
        </application> 
    </compatibility>

Now Environment.OSVersion includes the correct data for Windows 8.1 and Windows 10 and not 6.2 to indicate you run Windows 8. This is a change since Windows 8.1.

like image 186
magicandre1981 Avatar answered Oct 09 '22 20:10

magicandre1981