Closed firatesmer closed 7 years ago
Hi, do you have more specific information what is wrong? Compile problems or it does not work properly?
Sorry, forgot to tell details. (btw I changed the app's framework version to 4 and it's working. just wondering why 4.5.2 doesn't work))
digitalProductId is null
App.config => `<?xml version="1.0" encoding="utf-8" ?>
Here you go i fixed it, replace the GetWindowsProductKey() code with my code below and it should work
` public static string GetWindowsProductKey() { RegistryKey localKey; if (Environment.Is64BitOperatingSystem) { localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); } else { localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); }
var value = (byte[])localKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue("DigitalProductId");
var digitalProductId = value;
var isWin8OrUp =
(Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor >= 2)
||
(Environment.OSVersion.Version.Major > 6);
var productKey = isWin8OrUp ? DecodeProductKeyWin8AndUp(digitalProductId) : DecodeProductKey(digitalProductId);
localKey.Close(); //why didnt you close the key?
return productKey;
}`
Would be great to hear if suggested fix by @PhilipMur works for you @almorax, so I can fix it...
@PhilipMur Working with your way. Thanks mate!
I tried the same code on different framework version app (4.5.2) and it doesn't work. Can you tell me why lower framework version supports this code but higher doesn't? Your app is .net framework 4.