First of all add these namespaces :
using Microsoft.Win32; using System.Collections;
After that add this function.:
public enum Key { Windows };
public static byte[] GetRegistryDigitalProductId(Key key)
{
byte[] digitalProductId = null;
RegistryKey registry = null;
switch (key)
{
case Key.Windows:
registry =
Registry.LocalMachine.
OpenSubKey(
@"SOFTWARE\Microsoft\Windows NT\CurrentVersion",
false);
break;
}
if (registry != null)
{
digitalProductId = registry.GetValue("DigitalProductId")
as byte[];
registry.Close();
}
return digitalProductId;
}
public static string DecodeProductKey(byte[] digitalProductId)
{
const int keyStartIndex = 52;
const int keyEndIndex = keyStartIndex + 15;
char[] digits = new char[]
{
'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R',
'T', 'V', 'W', 'X', 'Y', '2', '3', '4', '6', '7', '8', '9',
};
const int decodeLength = 29;
const int decodeStringLength = 15;
char[] decodedChars = new char[decodeLength];
ArrayList hexPid = new ArrayList();
for (int i = keyStartIndex; i <= keyEndIndex; i++)
{
hexPid.Add(digitalProductId[i]);
}
for (int i = decodeLength - 1; i >= 0; i--)
{
if ((i + 1) % 6 == 0)
{
decodedChars[i] = '-';
}
else
{
int digitMapIndex = 0;
for (int j = decodeStringLength - 1; j >= 0; j--)
{
int byteValue = (digitMapIndex << 8) | (byte)hexPid[j];
hexPid[j] = (byte)(byteValue / 24);
digitMapIndex = byteValue % 24;
decodedChars[i] = digits[digitMapIndex];
}
}
}
return new string(decodedChars);
}
I always love to get the result via messagebox so add this piece of code to form_load or something
byte[] results = Form1.GetRegistryDigitalProductId(Form1.Key.Windows);
MessageBox.Show(Form1.DecodeProductKey(results),"HWID()",MessageBoxButtons.OK,MessageBoxIcon.Information);
Debug and there you get the product keyhave fun :)


6 comments
don't work
Replycan you give me this in a project
Hey sorry there was a mistake, you need these namespaces
Replyusing Microsoft.Win32;
using System.Collections;
add them and try if it didn't work let me know :)
Thanks
how can we add an office serial?
Replyit gave me wrong nomber BBBBB-BBBBBB-BBBBBB-BBBBBB-BBBBBB
Replydoesn't get the right code
ReplyI'll admit, I've been running Windows 7 for six months now: Windows 7 is quite simply faster, more stable, boots faster, goes to sleep faster Even the preproduction version of Windows 7 was better than my Vista with SP2
ReplyImportance Keyboards in Computer Game
Post a Comment
Note: Only a member of this blog may post a comment.