How can I detect if my app is running on Windows 10

后端 未结 7 1343
清酒与你
清酒与你 2020-12-09 01:17

I\'m looking for a means to detect if my C# app is running on Windows 10.

I had hoped that Environment.OSVersion would do the trick, but this seems to r

相关标签:
7条回答
  • 2020-12-09 02:00

    If you look at registry you will found environment name:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName
    

    For example my product name is Windows 10 Home:

    With this code you get if it 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");
     }
    

    Note: Add using Microsoft.Win32; to your usings.

    0 讨论(0)
提交回复
热议问题