string strProcessorId = string.Empty;
SelectQuery query = new SelectQuery("Win32_processor");
ManagementObjectSearcher search = new ManagementObjectSearcher(query);
foreach (ManagementObject info in search.Get())
{
strProcessorId = info["processorId"].ToString();
}
Console.WriteLine(strProcessorId);
Console.ReadLine();
它为行
提供错误strProcessorId = info["processorId"].ToString();
错误是:Object reference not set to an instance of an object.
如何删除此错误
答案 0 :(得分:1)
WMI属性名称可能区分大小写。尝试:
strProcessorId = info["ProcessorId"].ToString();
它可能也有助于正确地大写Win32_Processor类的名称:
SelectQuery query = new SelectQuery("Win32_Processor");
答案 1 :(得分:1)
试
string strProcessorId = string.Empty;
SelectQuery query = new SelectQuery("Win32_processor");
ManagementObjectSearcher search = new ManagementObjectSearcher(query);
foreach (ManagementObject info in search.Get())
{
strProcessorId = info["ProcessorID"].ToString();
}
Console.WriteLine(strProcessorId);
Console.ReadLine();
认为这只是缺少资本意味着返回null