11

Is there any easy way to get Windows Edition (Home, Professional, etc.)?

SiberianGuy
  • 24,674
  • 56
  • 152
  • 266
  • Related post - [Detect Windows version in .NET](https://stackoverflow.com/q/2819934/465053) – RBT Sep 20 '21 at 04:25
  • Sort of. Use [this class](http://www.csharp411.com/wordpress/wp-content/uploads/2009/01/OSInfo.cs) in [this way](http://www.csharp411.com/determine-windows-version-and-edition-with-c/). – Paul Sasik Dec 10 '10 at 04:58

3 Answers3

6

Couple of ways of doing this:

  1. You could parse the caption field of the Win32_OperatingSystem class in WMI.
  2. You could look at OSProductSuite and OperatingSystemSKU fields in the Win32_OperatingSystem class in WMI.
  3. You could port this C++ program using P/Invoke.
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
  • 1
    WMI calls take 50ms or more. Your C++ code doesn't even give the edition name. If you want something quick and detailed, just look in the registry. HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName – Sophit Apr 29 '16 at 00:11
  • 1
    @Sophit: 1. re: 50ms: not in my experience, at least on the local machine. 2. How often are you logging the OS caption that performance in this area matters anyway? 3. The registry is not an API and that key is not contractual. – Billy ONeal Apr 29 '16 at 04:17
4

If you reference the Microsoft.VisualBasic.Devices namespace you can do this:

ComputerInfo computerInfo = new ComputerInfo();
string fullName = computerInfo.OSFullName; // i.e. "Microsoft Windows 7 Ultimate"

You can use Microsoft.VisualBasic in your c# apps - it's just like any other library.

Jason
  • 8,400
  • 10
  • 56
  • 69
  • When using from VB.NET, it's just `My.Computer.Info.OSFullName`. Note the result is localized though, so not good for parsing. Unlike it, the [registry value](http://stackoverflow.com/questions/4405761/get-windows-edition#comment61415777_4405791) is not localized. – GSerg Feb 05 '17 at 14:09
1

Easy answer? Just look in the registry.

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CSDVersion

It doesn't have the overhead of WMI (50ms every call), and it gives the full name.

RBT
  • 24,161
  • 21
  • 159
  • 240
Sophit
  • 491
  • 2
  • 8
  • For something that you only need to do once and cache it (the OS can't change versions without rebooting first), 50ms is not that big of a deal. – Scott Chamberlain Apr 29 '16 at 00:15
  • This is a full proof answer which gives accurate information in all scenarios. Only thing is that your application might require admin privileges to be able to access the registry. There are some more useful keys over there namely InstallationType (Client/Server), CurrentMajorVersionNumber, CurrentMinorVersionNumber, CurrentBuildNumber, EditionID (Enterprise, professional, Home, etc.) which anyone can leverage. – RBT Sep 20 '21 at 04:26
  • This does not provide accurate information with the new Enterprise/Subscription Activation technology. My machine is Windows 11 Enterprise, but ProductName says Windows 10 Pro. – ElizabethGreene Jan 19 '23 at 16:59