Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the Windows product name in Windows 11?

Windows 11, released yesterday, reports itself as Windows 10.0 just about everywhere - RtlGetVersion says 10.0, and if you ask VerifyVersionInfo if you are 11.0 or greater, it says no.

There seems to be no new GUID to shove into app.manifest to say "hey I support Windows 11" like there was for Windows 7, 8, 8.1, and 10.

Currently I rely on HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName to tell me what the current version of Windows is, but on my machine that I've upgraded, it still says "Windows 10 Enterprise", not "Windows 11 Enterprise".

There appears to only be a single place in the registry that contains the text "Windows 11" and that is the BCD section (boot configuration), which can also be renamed so I don't want to touch that.

So far I have only identified a handful of methods to tell if I am running on Windows 11:

  1. Invoke WMI to query Win32_OperatingSystem and check the Name property, which simply says "Windows 11". This is incomplete (it does not include the SKU such as "Enterprise"), and WMI is relatively slow and slightly brittle, so it's not an acceptable solution for my use-case.

  2. Check the build number to see if it is above 21996 (beta builds) or 22000 (first public release). As above, this won't include the SKU, and would require some manual jiggery-pokery in order to build the full string.

  3. Run sysinfo and parse the output. This is quite slow, and possibly brittle (I haven't checked but the output might be localised into different languages).

  4. winver knows, but it's a GUI application so I can't exactly query it programmatically.

Does anyone have any other ideas on how to get the string "Windows 11 Enterprise" (or "Windows 11 Pro", etc. as the case may be) out of my operating system in a performant and complete manner? Where do WMI, sysinfo, and winver get it from?

I need to do this from a .NET library, but P/Invokes / native function calls are acceptable solutions.

like image 254
yaakov Avatar asked Oct 06 '21 06:10

yaakov


People also ask

How do I find my Windows 11 details?

Find Windows 11 System Specs To get the basic system information about your system, you can use what's already built into Windows 11. To get started, head to Start > Settings > System > About. Here you will find basic device specs like CPU, installed RAM, system type, and version of Windows 11.

How do I find the product key for Windows 11?

Use the command prompt in Windows 11 Open the Windows 11 search tool and type “command.” Find command prompt (Figure A) in the search results and click the Run As Administrator link to reach the command prompt screen. The command will reveal your original Windows 11 product key right there on the command prompt screen.

How do I Find my Windows 11 product key?

If you’re using an OEM copy of Windows 11, both the green and blue boxes display your product key. If you installed a version of Windows 11 you purchased yourself, the green box is the key currently in use. Once you have the key you can write it down or save it to a file on your computer.

What is a Windows 10 product key?

A Windows product key is a 25-character code used to activate Windows. It looks like this: PRODUCT KEY: XXXXX-XXXXX-XXXXX-XXXXX-XXXXX. Depending on how you got your copy of Windows 10, you'll need either a 25-character product key or a digital license to activate it.

How do I know if my Windows 10 software is genuine?

How to tell your software is genuine. Find your product key in the confirmation email you received after buying Windows 10 or in a digital locker accessible through the retailer’s website. The product key is in the confirmation email you received after buying your digital copy of Windows.

How to get Windows 11 license key for laptop?

Just turn back your laptop and look for a 25-character product key. Keep in mind, if you bought the laptop running Windows 10 or 7, the license key will still work without any issues on your upgraded Windows 11 PC. However, if you bought the product key online, you need to look for the email or invoice slip and find the license key.


Video Answer


4 Answers

Leaving this here so that I can find it later:

It seems that Windows itself (e.g. winver) gets this information from Windows branding - specifically from the resource table in %WinDir%\Branding\Basebrd\en-US\basebrd.dll.mui.

To access this one could use the private APIs in %WinDir%\System32\winbrand.dll. Specifically, the function BrandingFormatString which accepts a wide string (LPW[C]STR) and returns a wide string.

e.g. BrandingFormatString("%WINDOWS_LONG%") returns "Windows 11 Pro" on my home PC.

I do not know the lifecycle semantics of the resulting string, i.e. if/when/how it should be freed.

The following code serves as a functional proof-of-concept (C# 9.0):

using System;
using System.Runtime.InteropServices;

[DllImport("winbrand.dll", CharSet = CharSet.Unicode)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
static extern string BrandingFormatString(string format);

Console.WriteLine(BrandingFormatString("Hello World from %WINDOWS_LONG%!"));

like image 128
yaakov Avatar answered Nov 05 '22 04:11

yaakov


tldr - Using the EditionID and the CurrentBuild from the CurrentVersion in the registry seems to be a reliable way to determine Win10 vs Win11 and the "edition" of the software. EditionID is "Professional" on Windows 10 Pro and Windows 11 Pro, and CurrentBuild >= ~22000 tells you if it is 10 or 11.

The collection of registry values in the HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion reveals what feels like a lack of planning on Microsoft's part. There's ReleaseId, which is a number that changed with each Windows 10 release (e.g., 1903, 1909, 2004,...) until its last change for Windows 10 20H2, where it changed to 2009. At the same time, DisplayVersion was added, and was set to 20H2.

Then Windows 10 21H1 released, and ReleaseId inexplicably stayed at 2009.

The fact that both current Windows 10 and Windows 11 releases can have the same DisplayVersion (e.g., 21H2 when Windows 10 21H2 releases soon) and ProductName (e.g., Windows 10 Pro) is really head-scratching. (Thanks @yaakov for catching my mistake saying it was 21H1.)

like image 38
aggieNick02 Avatar answered Nov 05 '22 02:11

aggieNick02


The following code has been tested on Windows XP, 7, 10, 11. It works on 32 bit and 64 bit operating systems. It works inside 32 bit and 64 bit applications.

The following strings will be generated:

  • "Microsoft Windows XP, Build 2600, 32 bit"
  • "Windows 7 Ultimate, Build 7601, 64 bit"
  • "Windows 10 Enterprise LTSC 2019, Version 1809, Build 17763, 64 bit"
  • "Windows 10 Pro, Version 1909, Build 18362, 64 bit"
  • "Windows 11 Professional, Version 21H2, Build 22000, 64 bit"

Put the code into a static constructor so it executes only once and writes the version into a static variable.

static String ms_OperatingSystem;

static Constructor()
{
    try
    {
        String s_KernelPath = Path.Combine(Environment.SystemDirectory,"Kernel32.dll");
        FileVersionInfo k_Kernel = FileVersionInfo.GetVersionInfo(s_KernelPath);

        // on 32 bit Windows this will read the 32 bit hive instead
        using (RegistryKey i_HKLM = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
        {
            using (RegistryKey i_RegVer = i_HKLM.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion", false))
            {
                // Kernel32.dll on Windows 11 has Product Version 10.0.22000.120
                if (k_Kernel.ProductMajorPart == 10 && k_Kernel.ProductBuildPart >= 22000)
                {
                    ms_OperatingSystem = "Windows 11";

                    Object o_Edition = i_RegVer.GetValue("EditionID"); // "Professional"
                    if (o_Edition is String)
                        ms_OperatingSystem += " " + o_Edition;
                }
                else
                {
                    // "Microsoft Windows XP"
                    // "Windows 7 Ultimate"
                    // "Windows 10 Pro"  (same string on Windows 11. Microsoft SUCKS!)
                    ms_OperatingSystem = (String)i_RegVer.GetValue("ProductName");
                }

                // See: https://en.wikipedia.org/wiki/Windows_10_version_history
                // Windows 10 older releases --> "2009" (invalid if DisplayVersion exists)
                Object o_ReleaseID = i_RegVer.GetValue("ReleaseId");

                // Windows 10 latest release --> "21H1"
                // Windows 11 first  release --> "21H2"
                Object o_DispVer = i_RegVer.GetValue("DisplayVersion");

                // Use ReleaseID ONLY if DisplayVersion does not exist in registry!
                     if (o_DispVer   is String) ms_OperatingSystem += ", Version " + o_DispVer;
                else if (o_ReleaseID is String) ms_OperatingSystem += ", Version " + o_ReleaseID;

                ms_OperatingSystem += ", Build " + k_Kernel.ProductBuildPart;

                if (Environment.Is64BitOperatingSystem) ms_OperatingSystem += ", 64 bit";
                else                                    ms_OperatingSystem += ", 32 bit";
            }
        }
     }
     catch (Exception Ex)
     {
        ms_OperatingSystem = Ex.Message;
     }
}
like image 25
Elmue Avatar answered Nov 05 '22 02:11

Elmue


I created a remote support tool for desktop admins (see http://www.appslife-rdt.appspot.com) In VB.Dot.Net i used a call to the WMI space Win32_OperatingSystem and got the "Name" value back. This then needs to be split to get the first object which is what you require. i.e.

Dim query2 As New SelectQuery("SELECT * FROM Win32_OperatingSystem")
Dim searcher2 As New ManagementObjectSearcher(objManagementScope2, query2, QueryOptions)
        For Each mo As ManagementObject In searcher2.[Get]()
                           OSname = mo("Name")
        Next

        Dim array1 As Array = Nothing
        array1 = Split(OSname, "|")
        OSname = array1(0).ToString

OSname then gives you the "Windows 11 Pro" or "Windows XP Professional" that you require.

I also get the OSVersion with the latest patch update info from registry as follows if needed...

THIS IS FOR CLIENT VERSIONS 10/11 :-

.SetPropertyValue("sSubKeyName", "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Update\TargetingInfo\Installed\Client.OS.rs2.amd64") .SetPropertyValue("sValueName", "Version")

THIS IS FOR SERVER VERSIONS 2019 :-

.SetPropertyValue("sSubKeyName", "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Update\TargetingInfo\Installed\Server.OS.amd64") .SetPropertyValue("sValueName", "Version")

Hope this is of help.

like image 36
Tim Avatar answered Nov 05 '22 03:11

Tim