mrpeardotnet / WinProdKeyFinder

Windows Product Key Finder written in C#.
http://www.mrpear.net
MIT License
130 stars 42 forks source link

Framework Issue #3

Closed firatesmer closed 7 years ago

firatesmer commented 7 years ago

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.

mrpeardotnet commented 7 years ago

Hi, do you have more specific information what is wrong? Compile problems or it does not work properly?

firatesmer commented 7 years ago

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" ?>

` ![image](https://cloud.githubusercontent.com/assets/15785611/24470901/22b10ef2-14c9-11e7-8158-3e6d6570e568.png)
PhilipMur commented 7 years ago

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;

    }`
mrpeardotnet commented 7 years ago

Would be great to hear if suggested fix by @PhilipMur works for you @almorax, so I can fix it...

firatesmer commented 7 years ago

@PhilipMur Working with your way. Thanks mate!