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

后端 未结 7 1386
清酒与你
清酒与你 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 01:55

    Try this one:

    string subKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion";
    Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine;
    Microsoft.Win32.RegistryKey skey = key.OpenSubKey(subKey);
    
    string name = skey.GetValue("ProductName").ToString();
    

    and then you can just use an if clause:

    if(name.Contains("Windows 10"))
    {
        //... procedures
    }
    else
    {
       //... procedures
    }
    

提交回复
热议问题