获取处理器 ID 或某些硬件信息的最安全方法
我需要获取任何信息来识别一台机器,到目前为止我所使用的内容如下:
internal static string GetProcessorId()
{
try
{
StringBuilder sb = new StringBuilder();
using (System.Management.ManagementClass theClass = new System.Management.ManagementClass("Win32_Processor"))
{
using (System.Management.ManagementObjectCollection theCollectionOfResults = theClass.GetInstances())
{
foreach (System.Management.ManagementObject currentResult in theCollectionOfResults)
{
sb.Append(currentResult["ProcessorID"].ToString());
}
}
}
return sb.ToString();
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
return "";
}
}
但是当我在 Windows XP 上(从虚拟机)上运行它时,我的 currentResult["ProcessorID"]
为null
。我不确定是否是因为我使用的是虚拟机,但可能是因为是XP。无论如何,我不太信任这段代码。足够安全吗?我应该通过其他方式获取计算机 ID 吗?这是我正在开发的许可系统的一部分。
I need to get any info to identify a machine and what I was using so far was the following:
internal static string GetProcessorId()
{
try
{
StringBuilder sb = new StringBuilder();
using (System.Management.ManagementClass theClass = new System.Management.ManagementClass("Win32_Processor"))
{
using (System.Management.ManagementObjectCollection theCollectionOfResults = theClass.GetInstances())
{
foreach (System.Management.ManagementObject currentResult in theCollectionOfResults)
{
sb.Append(currentResult["ProcessorID"].ToString());
}
}
}
return sb.ToString();
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
return "";
}
}
But when I run this on Windows XP (from a Virtual Machine), my currentResult["ProcessorID"]
is null
. I'm not sure if it is because I'm using a virtual machine, but it might be because is XP. Anyway, I'm not very trustful of this code. Is it safe enough? Should I get a computer Id some other way? This is all part of a licensing system I'm developing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于我编写的一个小工具(Windows Forms .NET 2.0),我需要类似的东西。
我编写了一个帮助程序类,它通过
GetVolumeInformation
函数的PInvoke简单地使用一些常见信息,例如HDD序列号。这绝不是真正安全或防弹的,但足够准确以满足我的需求。
(如果您有兴趣,这个就是这个工具,如果我可以链接到的话)
For a small tool I wrote (Windows Forms .NET 2.0), I needed something similar.
I wrote a helper class that simply uses some common information like HDD serial number through PInvoke of the
GetVolumeInformation
function.This is by no way really safe or bullet-proof, but accurate enough to fit my needs.
(If you are interested this is the tool, if I'm allowed to link to)
即使它有效,也不会达到您想要的效果。 ProcessorID 为您提供过程产品(具有 Y 和 Z 功能的 Pentium X)的标识,而不是有关 CPU 的特定实例的标识。是这样描述的:
IBM PC 硬件没有任何防伪硬件标识。
Even if it worked, it wouldn't do what you want. The ProcessorID gives you an identification of the process product (Pentium X with features Y and Z), not about the specific instance of the CPU. It is described thus:
The IBM PC hardware doesn't have any kind of fake-proof hardware identification.