我编写了一个程序,该程序可以获取Windows产品密钥以通过Windows注册表检查激活。 我使用Open Base Key来获得适合于字符串和二进制值的本地计算机。 但是,当我使用Open Remote Base Key从远程计算机获取产品ID时,它仅返回字符串值,而对于二进制值则返回null。
首先:在当前PC上测试时可以。我将代码更改为远程。它返回空值(请参见下面的代码) 下一步:使用代码,我得到一个字符串值。这是工作。但是对于二进制文件,它返回null
try
{
//This get reg info from current PC
//RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
//This get reg info from remote PC
RegistryKey key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, Environment.MachineName);
string keyPath = @"Software\Microsoft\Windows NT\CurrentVersion";
byte[] rpk = (byte[])key.OpenSubKey(keyPath).GetValue("DigitalProductId");
Console.WriteLine(key.OpenSubKey(keyPath).GetValue("InstallDate"));
Console.WriteLine(key.OpenSubKey(keyPath).GetValue("InstallDate"));
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(Exception ex)
{
Console.WriteLine(ex);
return "No Found";
}
对象引用未设置为对象的实例