public static string GetWindowsProductKeyFromRegistry() { RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32); RegistryKey registryKey2 = registryKey.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"); object obj = (registryKey2 != null) ? registryKey2.GetValue("DigitalProductId") : null; bool flag = obj == null; string result; if (flag) { result = "Failed to get DigitalProductId from registry"; } else { byte[] digitalProductId = (byte[])obj; registryKey.Close(); bool flag2 = (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor >= 2) || Environment.OSVersion.Version.Major > 6; result = KeyDecoder.GetWindowsProductKeyFromDigitalProductId(digitalProductId, flag2 ? DigitalProductIdVersion.Windows8AndUp : DigitalProductIdVersion.UpToWindows7); } return(result); }
public static string GetWindowsProductKeyFromDigitalProductId(byte[] digitalProductId, DigitalProductIdVersion digitalProductIdVersion) { return((digitalProductIdVersion == DigitalProductIdVersion.Windows8AndUp) ? KeyDecoder.DecodeProductKeyWin8AndUp(digitalProductId) : KeyDecoder.DecodeProductKey(digitalProductId)); }