Richard Everett Richard Everett - 1 year ago 125
C# Question

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

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

I had hoped that

would do the trick, but this seems to return a
on Windows 8.1 and Windows 10.

Other solutions such as this don't seem to distinguish between Windows 8 and Windows 10 either.

Any suggestions?


Why do I need to do this?

Because I'm using a WinForms WebBrowser control to host an OAuth page that crashes and burns in older IE versions (my app connects to a user's Nest account...).

By default, the WebBrowser control emulates IE7. Using a Registry key, you can tell it to emulate the latest version of IE that is installed on the host PC. However, the value that worked up to Windows 8.1 (and pre-releases of Windows 10) does not work in the final version of Windows 10.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download