Saturday, February 19, 2011

How can i get the cpu information in .net?

like whether it is pentium or AMD etc.

From stackoverflow
  • You can find a great Example for this here: http://www.codeproject.com/KB/system/GetHardwareInformation.aspx

    But its basically in System.Management

    suhair : Thanks, that is quite useful.
  • The System.Management Namespace Provides access to a rich set of management information and management events about the system, devices, and applications instrumented to the Windows Management Instrumentation (WMI) infrastructure.

    The Win32 Processor WMI class represents a device that can interpret a sequence of instructions on a computer running on a Windows operating system. On a multiprocessor computer, one instance of the Win32_Processor class exists for each processor. The class includes a Processor family type field, encoding things like AMD Opteron Processor Family.

    An example of C# issuing WMI query is at the end of the page.

  • Please note that this is from vs2003

     using(ManagementObjectSearcher win32Proc = new ManagementObjectSearcher("select * from Win32_Processor"),
              win32CompSys = new ManagementObjectSearcher("select * from Win32_ComputerSystem"),
              win32Memory = new ManagementObjectSearcher("select * from Win32_PhysicalMemory"))
           {
            foreach (ManagementObject obj in win32Proc.Get())
            {
             clockSpeed = obj["CurrentClockSpeed"].ToString();
             procName = obj["Name"].ToString();
             manufacturer = obj["Manufacturer"].ToString();
             version = obj["Version"].ToString();
    
    
            }
    

0 comments:

Post a Comment