GWK.GetWindowsProductKeyFromRegistry Method
public static string GetWindowsProductKeyFromRegistry()
This language is not supported or no code example is available.
Return Value
string
public static string GetWindowsProductKeyFromRegistry()
{
var localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32);
var registryKeyValue = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion")?.GetValue("DigitalProductId");
if (registryKeyValue == null)
return "Failed to get DigitalProductId from registry";
var digitalProductId = (byte[])registryKeyValue;
localKey.Close();
var isWin8OrUp = Environment.OSVersion.Version.Major == 6 &&
Environment.OSVersion.Version.Minor >= 2 ||
Environment.OSVersion.Version.Major > 6;
return GetWindowsProductKeyFromDigitalProductId(digitalProductId, isWin8OrUp ? DigitalProductIdVersion.Windows8AndUp : DigitalProductIdVersion.UpToWindows7);
}
This language is not supported or no code example is available.
.NET Framework
Supported in: 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Core
Supported in: 5.0+, 6.0+