getInfo method
Implementation
@visibleForTesting
WindowsDeviceInfo getInfo() {
_rtlGetVersion ??= DynamicLibrary.open('ntdll.dll').lookupFunction<
Void Function(Pointer<OSVERSIONINFOEX>),
void Function(Pointer<OSVERSIONINFOEX>)>('RtlGetVersion');
final systemInfo = getSYSTEMINFOPointer();
final osVersionInfo = getOSVERSIONINFOEXPointer();
final buildLab = getRegistryValue(
HKEY_LOCAL_MACHINE,
'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\',
'BuildLab',
'',
) as String;
final buildLabEx = getRegistryValue(
HKEY_LOCAL_MACHINE,
'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\',
'BuildLabEx',
'',
) as String;
final digitalProductId = getRegistryValue(
HKEY_LOCAL_MACHINE,
'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\',
'DigitalProductId',
Uint8List.fromList([]),
) as Uint8List;
final displayVersion = getRegistryValue(
HKEY_LOCAL_MACHINE,
'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\',
'DisplayVersion',
'',
) as String;
final editionId = getRegistryValue(
HKEY_LOCAL_MACHINE,
'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\',
'EditionID',
'') as String;
final installDate = DateTime.fromMillisecondsSinceEpoch(1000 *
getRegistryValue(
HKEY_LOCAL_MACHINE,
'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\',
'InstallDate',
0,
) as int);
final productId = getRegistryValue(
HKEY_LOCAL_MACHINE,
'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\',
'ProductId',
'',
) as String;
var productName = getRegistryValue(
HKEY_LOCAL_MACHINE,
'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\',
'ProductName',
'',
) as String;
final registeredOwner = getRegistryValue(
HKEY_LOCAL_MACHINE,
'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\',
'RegisteredOwner',
'',
) as String;
final releaseId = getRegistryValue(
HKEY_LOCAL_MACHINE,
'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\',
'ReleaseId',
'',
) as String;
final deviceId = getRegistryValue(
HKEY_LOCAL_MACHINE,
'SOFTWARE\\Microsoft\\SQMClient\\',
'MachineId',
'',
) as String;
GetSystemInfo(systemInfo);
// Use `RtlGetVersion` from `ntdll.dll` to get the Windows version.
_rtlGetVersion!(osVersionInfo);
// Handle [productName] for Windows 11 separately (as per Raymond Chen's comment).
// https://stackoverflow.com/questions/69460588/how-can-i-find-the-windows-product-name-in-windows-11
if (osVersionInfo.ref.dwBuildNumber >= 22000) {
productName = productName.replaceAll('10', '11');
}
final data = WindowsDeviceInfo(
numberOfCores: systemInfo.ref.dwNumberOfProcessors,
computerName: getComputerName(),
systemMemoryInMegabytes: getSystemMemoryInMegabytes(),
userName: getUserName(),
majorVersion: osVersionInfo.ref.dwMajorVersion,
minorVersion: osVersionInfo.ref.dwMinorVersion,
buildNumber: osVersionInfo.ref.dwBuildNumber,
platformId: osVersionInfo.ref.dwPlatformId,
csdVersion: osVersionInfo.ref.szCSDVersion,
servicePackMajor: osVersionInfo.ref.wServicePackMajor,
servicePackMinor: osVersionInfo.ref.wServicePackMinor,
suitMask: osVersionInfo.ref.wSuiteMask,
productType: osVersionInfo.ref.wProductType,
reserved: osVersionInfo.ref.wReserved,
buildLab: buildLab,
buildLabEx: buildLabEx,
digitalProductId: digitalProductId,
displayVersion: displayVersion,
editionId: editionId,
installDate: installDate,
productId: productId,
productName: productName,
registeredOwner: registeredOwner,
releaseId: releaseId,
deviceId: deviceId,
);
calloc.free(systemInfo);
calloc.free(osVersionInfo);
return data;
}