【发布时间】:2011-06-02 17:34:36
【问题描述】:
我需要获取任何信息来识别机器,到目前为止我使用的是以下内容:
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吗?这都是我正在开发的许可系统的一部分。
【问题讨论】:
-
可能重复:stackoverflow.com/questions/1101772/… 我知道 VMWare 不支持“ProcessorID”。
-
@Cody Gray:你的意思是 VMWare 不模拟英特尔 CPUID 指令吗?还是您的意思是每个英特尔处理器应该具有的硬编码 ID(可以在 BIOS 中关闭...)
-
@JimR:是的。我的意思是,正如问题所述,返回的值将是
null。请在他们的论坛上查看this thread 了解更多信息。 -
@Cody Gray:我认为您的意思是 Virtual Box,而不是 VMWare。你的链接也支持我的想法。我记得在 VMWare 支持处理器 ID 之前,过去使用一些延迟软件存在许可问题......该软件现在可以工作,所以这就是我问的原因。
-
@JimR:你是对的。我的意思是 Virtual Box,而不是 VMWare。有太多具有相似名称的虚拟化实用程序......无论哪种方式,关键是它并不总是有效。