Liest aus der Windows Registry den Windows CD Key aus.
namespace CD_Key
{
public class Win32
{
#region Properties
/// <summary>
/// Reads the Windows CD key from the registry and returns it as string separated by '-' chars.
/// </summary>
public static string WindowsCDKey
{
get
{
RegistryKey rKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
byte[] rpk = (byte[])rKey.GetValue("DigitalProductId", new byte[0]);
string strKey = "";
const int iRPKOffset = 52;
const string strPossibleChars = "BCDFGHJKMPQRTVWXY2346789";
int i = 28;
do
{
long lAccu = 0;
int j = 14;
do
{
lAccu *= 256; lAccu += Convert.ToInt64(rpk[iRPKOffset + j]);
rpk[iRPKOffset + j] =
Convert.ToByte(
Convert.ToInt64(Math.Floor((float)lAccu / 24.0f)) & Convert.ToInt64(255)
);
lAccu %= 24;
j -= 1;
}
while (j >= 0);
i -= 1;
strKey = strPossibleChars[(int)lAccu].ToString() + strKey;
if ((0 == ((29 - i) % 6)) && (-1 != i))
{
i -= 1;
strKey = "-" + strKey;
}
}
while (i >= 0);
return strKey;
}
}
/// <summary>
/// Reads the Windows CD key from the registry and returns it as string array.
/// </summary>
public static string[] WindowsCDKeyParts
{
get
{
string[] strKeyParts = WindowsCDKey.Split('-');
return strKeyParts;
}
}
#endregion
}
}
2 Kommentare zum Snippet