Skip to content

Instantly share code, notes, and snippets.

@JunTaoLuo
Created October 22, 2018 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JunTaoLuo/158b1b9284daf84afbe3e8cb9988fc48 to your computer and use it in GitHub Desktop.
Save JunTaoLuo/158b1b9284daf84afbe3e8cb9988fc48 to your computer and use it in GitHub Desktop.
WindowsVersions
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);
}
}
}
<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