我一直在使用下面的代碼來獲取Windows許可證密鑰。它工作很長時間。但是現在我發現它可以在Windows 7(x64)上運行,但在Windows 7 x64上可以運行而不是。C#獲取Windows CD密鑰
原因:DigitalProductID
註冊價值只包含我們正在尋找的64位操作系統範圍內的零。所以結果它BBBBB-BBBBB-BBBBB-BBBBB-BBBBB
。爲什麼會這樣,我該如何解決這個問題?
public static string LicenseCDKey
{
get
{
try
{
byte[] rpk = (byte[])Registry.LocalMachine
.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion")
.GetValue("DigitalProductId");
string serial = "";
const string possible = "BCDFGHJKMPQRTVWXY2346789";
for (int i = 0; i < 25; i++)
{
int accu = 0;
for (int a = 0; a < 15; a++)
{
accu <<= 8;
accu += rpk[66 - a];
rpk[66 - a] = (byte)(accu/24 & 0xff);
accu %= 24;
}
serial = possible[accu] + serial;
if (i % 5 == 4 && i < 24)
{
serial = "-" + serial;
}
}
return serial;
}
catch
{
return ErrorString;
}
}
}
你改變輸出到x64,而不是該平臺的目標任何CPU? – 2012-04-04 18:56:47
不,因爲我回答了以下兩個答案,我正在使用AnyCPU。 – bytecode77 2012-04-04 19:43:17