I'm using GetVersionEx and GetProductInfo APIs via P-Invoke to detect edition of Windows 10 OS as per below code:
P-Invoke declarations:
[DllImport("Kernel32.dll")]
internal static extern bool GetProductInfo(
int osMajorVersion,
int osMinorVersion,
int spMajorVersion,
int spMinorVersion,
out int edition);
[DllImport("kernel32.dll")]
private static extern bool GetVersionEx(ref OSVERSIONINFOEX osVersionInfo);
[StructLayout(LayoutKind.Sequential)]
private struct OSVERSIONINFOEX
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
public short wServicePackMajor;
public short wServicePackMinor;
public short wSuiteMask;
public byte wProductType;
public byte wReserved;
}
Code:
var edition = "";
var osVersionInfo = new OSVERSIONINFOEX
{
dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX))
};
if (GetVersionEx(ref osVersionInfo))
{
if (osVersionInfo.dwMajorVersion == 10
&& osVersionInfo.wProductType == 1)
{
int ed;
if (GetProductInfo(Environment.OSVersion.Version.Major
, Environment.OSVersion.Version.Minor
, osVersionInfo.wServicePackMajor
, osVersionInfo.wServicePackMinor
, out ed))
{
switch (ed)
{
case PRODUCT_PROFESSIONAL:
edition = "Windows 10 Pro";
break;
case PRODUCT_PRO_WORKSTATION:
edition = "Windows 10 Pro for Workstations";
break;
case PRODUCT_EDUCATION:
edition = "Windows 10 Education";
break;
case PRODUCT_ENTERPRISE:
edition = "Windows 10 Enterprise";
break;
//case 0x1234:
// edition = "Windows 10 Enterprise 2019 LTSC";
// break;
//case 0x2345:
// edition = "Windows 10 Pro Education";
// break;
default:
edition = "Unknown";
break;
}
}
}
}
pdwReturnedProductType
is the out parameter in GetProductInfo
API which provides the value of edition as per the table given in the documentation. The documentation is missing the hex values for below editions:
I need these values to cover all editions in my code. Not sure why these codes are missing from official MS documentation.
Everything is documented in winnt.h
in Windows SDK (C:\Program Files (x86)\Windows Kits\10\Include\10.0.BUILDNUMBER.0\um)
#define PRODUCT_PRO_FOR_EDUCATION 0x000000A4
#define PRODUCT_ENTERPRISE_S 0x0000007D
This PRODUCT_ENTERPRISE_S is LTSB/LTSC version.
To check which LTSB/LTSC version you use, also read ReleaseID
from registry. 1809 is 2019 LTSC, 1607 is 2016 long term version LTSB.