Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Created April 9, 2016 03:45
Show Gist options
  • Select an option

  • Save mohemohe/44a09b9e9ce50afae9a7d2a9840cbc4f to your computer and use it in GitHub Desktop.

Select an option

Save mohemohe/44a09b9e9ce50afae9a7d2a9840cbc4f to your computer and use it in GitHub Desktop.
WMIを使用したOSバージョンチェック
static void Main(string[] args)
{
var version = GetOsVersion();
if (version.Major < 10)
{
Console.WriteLine(@"死ね");
}
else
{
Console.WriteLine(@"キミには人権がある");
}
}
static Version GetOsVersion()
{
var os = new ManagementObjectSearcher(@"SELECT * FROM Win32_OperatingSystem").Get().Cast<ManagementObject>().FirstOrDefault();
var version = os?[@"Version"]?.ToString();
return version != null ? new Version(version) : null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment