开发者

How to get Processor Id from win32 processor

开发者 https://www.devze.com 2023-03-20 12:29 出处:网络
string strProcessorId = string.Empty; SelectQuery query = new SelectQuery(\"Win32_processor\"); ManagementObjectSearcher search = new ManagementObjectSearcher(query);
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();

erro开发者_如何学Gor is: Object reference not set to an instance of an object.

how to remove this error


WMI property names are probably case-sensitive. Try:

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

It might also help to properly capitalize the name of the 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

0

精彩评论

暂无评论...
验证码 换一张
取 消