Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys I am just wondering does anyone know how to get memory usage from a WMI command. I can get the CPU easily enough but struggling with the memory.

What I have so far

C#
ManagementScope ms = new ManagementScope(@"\\" + server.Value + @"\root\cimv2");
SelectQuery sq = new SelectQuery("select * from Win32_PerfFormattedData_PerfOS_Processor");
ManagementObjectSearcher mos = new ManagementObjectSearcher(ms, sq);
   foreach (System.Management.ManagementObject mo in mos.Get())
   {
      var usage = mo["PercentProcessorTime"];
      Console.WriteLine(usage);
   }


Thanks guys
Posted

Hi,

Check this link:
How To: (Almost) Everything In WMI via C# Part 2: Processes[^]

This may give you an idea :)
 
Share this answer
 
It depends entirely on what you mean by 'memory usage'.

You can start by using Win32_OperatingSystem class: http://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx[^]

Example here: http://www.blackwasp.co.uk/GetMemory.aspx[^]
 
Share this answer
 
Comments
frostcox 20-Nov-14 13:49pm    
excellent thanks very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900