简体   繁体   English

如何从win32处理器获取处理器ID

[英]How to get Processor Id from win32 processor

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();

it gives error for line它给出了线路错误

strProcessorId = info["processorId"].ToString();

error is: Object reference not set to an instance of an object.错误是: Object reference not set to an instance of an object.

how to remove this error如何消除此错误

WMI property names are probably case-sensitive. WMI 属性名称可能区分大小写。 Try:尝试:

strProcessorId = info["ProcessorId"].ToString();

It might also help to properly capitalize the name of the Win32_Processor class:正确大写Win32_Processor class 的名称也可能会有所帮助:

SelectQuery query = new SelectQuery("Win32_Processor");

try尝试

    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();

think it was just the capital missing that meant a null was being returned认为只是缺少资本意味着 null 被退回

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM