Momir Gostimir

Momir Gostimir

  • NA
  • 54
  • 2.4k

CPU information label

Mar 31 2017 8:55 AM
Hi,
 
I am making a small winforms app that shows me system information. I have a problem when I use code below: 
 
 ManagementObjectSearcher procesor = new ManagementObjectSearcher("SELECT * FROM Win32_Proccesor");
            string cpu = string.Empty;

            foreach (ManagementObject mo in procesor.Get())
            {
                foreach (PropertyData property in mo.Properties)
                {
                    if (property.Name == "Description")
                    {
                        cpu = property.Value.ToString();
                    }
                }
            }

            cpuname.Text = cpu;
 
cpuname is my label that needs to change accordingly to cpu information that is provided from ManagmentObject. I get error:  'System.Management.ManagementException' occurred in System.Management.dll   in  --> foreach (ManagementObject mo in procesor.Get()) could you help me with this code?

Answers (5)