-
-
Save sk8tz/76bb6d3658bd2d8e9ef284a33bdfcdd6 to your computer and use it in GitHub Desktop.
Find percentage used physical memory - with aid of WMI code generator http://www.microsoft.com/en-ie/download/details.aspx?id=8572
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
using System; | |
using System.Management; | |
namespace WMIQuery | |
{ | |
public class UsedPhysicalMemoryQuery | |
{ | |
public static void Main() | |
{ | |
try | |
{ | |
ManagementObjectSearcher searcher = | |
new ManagementObjectSearcher("root\\CIMV2", | |
"SELECT * FROM Win32_OperatingSystem"); | |
foreach (ManagementObject queryObj in searcher.Get()) | |
{ | |
double free = Double.Parse(queryObj["FreePhysicalMemory"].ToString()); | |
double total = Double.Parse(queryObj["TotalVisibleMemorySize"].ToString()); | |
Console.WriteLine("Percentage used: {0}%", Math.Round(((total - free)/total * 100), 2)); | |
Console.Read(); | |
} | |
} | |
catch (ManagementException e) | |
{ | |
Console.WriteLine(value: e.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment