Created
July 6, 2018 21:30
-
-
Save mjs3339/7a444b49b4f0ddc21ecb4ae40ce6ac35 to your computer and use it in GitHub Desktop.
C# Get CPU Information using WMI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Dictionary<string, string> GetProcessorInfo() | |
{ | |
ManagementObjectCollection moc; | |
var Processor = new Dictionary<string, string>(); | |
try | |
{ | |
moc = new ManagementObjectSearcher("select * from Win32_Processor").Get(); | |
} | |
catch | |
{ | |
MessageBox.Show("Error: WMI API Not loaded."); | |
return Processor; | |
} | |
foreach (ManagementObject obj in moc) | |
{ | |
try | |
{ | |
Processor.Add("AddressWidth", obj["AddressWidth"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Architecture", obj["Architecture"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Availability", obj["Availability"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Caption", obj["Caption"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("CpuStatus", obj["CpuStatus"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("CreationClassName", obj["CreationClassName"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("CurrentClockSpeed", obj["CurrentClockSpeed"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("CurrentVoltage", obj["CurrentVoltage"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("DataWidth", obj["DataWidth"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Description", obj["Description"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("DeviceID", obj["DeviceID"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("ExtClock", obj["ExtClock"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Family", obj["Family"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("L2CacheSize", obj["L2CacheSize"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("L3CacheSize", obj["L3CacheSize"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Level", obj["Level"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("LoadPercentage", obj["LoadPercentage"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Manufacturer", obj["Manufacturer"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("MaxClockSpeed", obj["MaxClockSpeed"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Name", obj["Name"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("NumberOfCores", obj["NumberOfCores"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("NumberOfLogicalProcessors", obj["NumberOfLogicalProcessors"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("PowerManagementSupported", obj["PowerManagementSupported"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Processorid", obj["Processorid"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("ProcessorType", obj["ProcessorType"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Revision", obj["Revision"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Role", obj["Role"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("SocketDesignation", obj["SocketDesignation"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Status", obj["Status"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("StatusInfo", obj["StatusInfo"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Stepping", obj["Stepping"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("SystemName", obj["SystemName"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("UpgradeMethod", obj["UpgradeMethod"].ToString()); | |
} | |
catch | |
{ | |
} | |
try | |
{ | |
Processor.Add("Version", obj["Version"].ToString()); | |
} | |
catch | |
{ | |
} | |
} | |
return Processor; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment