I need a simple way of checking how much ram and fast the CPU of the host PC is. I tried WMI however the code I'm using
private long getCPU()
{
ManagementClass mObject = new ManagementClass("Win32_Processor");
mObject.Get();
return (long)mObject.Properties["MaxClockSpeed"].Value;
}
Throws a null reference exception. Furthermore, WMI queries are a bit slow and I need to make a few to get all the specs. Is there a better way?
To check your basic computer specs in Windows 10, click on the Windows start button, then click on the gear icon for Settings. In the Windows Settings menu, select System. Scroll down and select About. From here, you will see specs for your processor, RAM, and other system info.
If you're wondering how to check your clock speed, click the Start menu (or click the Windows* key) and type “System Information.” Your CPU's model name and clock speed will be listed under “Processor”.
Find Out How Much RAM You HaveOpen Settings > System > About and look for the Device Specifications section. You should see a line named "Installed RAM"—this will tell you how much you currently have.
http://dotnet-snippets.com/dns/get-the-cpu-speed-in-mhz-SID575.aspx
using System.Management;
public uint CPUSpeed()
{
ManagementObject Mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
uint sp = (uint)(Mo["CurrentClockSpeed"]);
Mo.Dispose();
return sp;
}
RAM can be found in this SO question: How do you get total amount of RAM the computer has?
You should use PerformanceCounter
class in System.Diagnostics
PerformanceCounter cpuCounter;
PerformanceCounter ramCounter;
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
public string getCurrentCpuUsage(){
cpuCounter.NextValue()+"%";
}
public string getAvailableRAM(){
ramCounter.NextValue()+"MB";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With