I was working with Microsoft Developer Support on this issue and wanted to share the information and solution that was concluded.
Some registry values under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion will be updated when upgrading to Windows 11; others will remain as they were on Windows 10 (or earlier). The major and minor version will remain 10.0 on Windows 11. Microsoft recommendation is that applications should use the relevant APIs to retrieve such information from the system (WMI, GetVersionEx, etc) rather than querying the registry
Also there were requests have already been submitted to change these registry key values and rejected by the Windows team. Updating the registry value to “Windows 11” can cause compatibility issues with existing applications that rely upon the registry value containing specific strings.
Hence we tried the following and fixed in our code to detect Windows 11. Sample snippets.
PS C:\> Get-WmiObject -Class Win32_OperatingSystem | Format-List -Property Caption
Caption : Microsoft Windows 11 Enterprise
- WMI C#: string osName= null;
var wmi = new ManagementObjectSearcher("select * from Win32_OperatingSystem");
foreach (ManagementObject obj in wmi.Get())
{
osName = obj["Caption"] as string;
break;
}
if(osName!=null)
return osName;