Hello,
I would like to know how to find the specs of the current running system such as the memory amount and processor speed in C#
Mateusz
Hello,
I would like to know how to find the specs of the current running system such as the memory amount and processor speed in C#
Mateusz
How to get system specs (processor, memory etc...) in C#?
SamLowry
I try to run the code above but get an exception saying
System.Runtime.InteropServices.COMException was unhandled
Message="Retrieving the COM class factory for component with CLSID {4590F811-1D3A-11D0-891F-00AA004B2E24} failed due to the following error: 80040154."
Source="System.Management"
ErrorCode=-2147221164
StackTrace:
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
...
The WMI log says:
(Sat Jul 08 16:27:17 2006.69014656) : Parsing MOF file: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CLR.mof
(Sat Jul 08 16:27:17 2006.69014718) : Compiler returned error 0x80040154(Sat Jul 08 16:28:20 2006.69078531) : Parsing MOF file: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet.mof
I can't seem to be able to use any WMI / Management classes.
Is there any way I can install the WMI again or fix this in any other way
Herbert Wang
I don't know if this will help, but it may be a place to start. Try looking for info on the functionality in the System.Management dll. I know this is how you get the processor ID:
private string GetProcessorID()
{
string sCpuInfo = String.Empty;
bool bSuccess = false;
//*** Declare Management Class
ManagementClass clsMgtClass = new ManagementClass( "Win32_Processor" );
ManagementObjectCollection colMgtObjCol = clsMgtClass.GetInstances();
//*** Loop Over Objects
foreach( ManagementObject objMgtObj in colMgtObjCol )
{
//*** Only return cpuInfo from first CPU
if( sCpuInfo == String.Empty )
{
sCpuInfo = objMgtObj.Properties["ProcessorId"].Value.ToString();
bSuccess = true;
}
}
return sCpuInfo;
}
Psilent Dev
To get info abt physical memmory use samble below. For CPU use "SELECT *
FROM Win32_Processor".
static void Main(string[] args)
{
double totalCapacity = 0;
ObjectQuery objectQuery = new ObjectQuery("select * from Win32_PhysicalMemory");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(objectQuery);
ManagementObjectCollection vals = searcher.Get();
foreach(ManagementObject val in vals)
{
totalCapacity += System.Convert.ToDouble(val.GetPropertyValue("Capacity"));
}
Console.WriteLine("Total Machine Memory = " + totalCapacity.ToString() + " Bytes");
Console.WriteLine("Total Machine Memory = " + (totalCapacity / 1024) + " KiloBytes");
Console.WriteLine("Total Machine Memory = " + (totalCapacity / 1048576) + " MegaBytes");
Console.WriteLine("Total Machine Memory = " + (totalCapacity / 1073741824 ) + " GigaBytes");
Console.ReadLine();
}
aniscartujo
in one of our win.net application, we simply showed standard Microsoft System Information application like this:
SysInfoPath = GetRegistryKey ( "LOCALMACHINE\SOFTWARE\Microsoft\Shared Tools\MSINFO\Path" )
create a process and run (SysInfoPath)
Dave Abrahams
Hi,
You can make use of GlobalMemoryStatusEx() and GetDiskFreeSpaceExA() methods of Kernel32.dll to get the memory space used and available.
And to get the processor speed, you can get the details from your registry (programmatically speaking, using Microsoft.Win32.RegistryKey)
HKEY_LOCALMACHINE\Hardware\DESCRIPTION\System\CentralProcessor\0
and get the value of the key ~MHz, which gives your processor speed.
Hope this helps.
Enjoy programming!!!!