Created
October 22, 2018 18:26
-
-
Save JunTaoLuo/158b1b9284daf84afbe3e8cb9988fc48 to your computer and use it in GitHub Desktop.
WindowsVersions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.Win32; | |
namespace TestVersion | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"); | |
var major = key.GetValue("CurrentMajorVersionNumber") as int?; | |
var minor = key.GetValue("CurrentMinorVersionNumber") as int?; | |
Console.WriteLine($"{major}.{minor}"); | |
Console.WriteLine(Environment.OSVersion); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp2.1</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0"/> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment