Created
October 10, 2013 11:33
-
-
Save happydeveloper/6916962 to your computer and use it in GitHub Desktop.
원도우 계열 운영체제 - 닷넷이 설치되어 있는 컴퓨터
닷넷 2.0 동작
메모리 사용량 체크
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.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Management; | |
namespace memoryUsage | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
ManagementClass cls = new ManagementClass("Win32_OperatingSystem"); | |
ManagementObjectCollection instance = cls.GetInstances(); | |
foreach (ManagementObject info in instance) | |
{ | |
Console.WriteLine("Memory Information ================================"); | |
Console.WriteLine("Total Physical Memory :{0:#,###} KB", info["TotalVisibleMemorySize"]); | |
Console.WriteLine("Free Physical Memory :{0:#,###} MB", info["FreePhysicalMemory"]); | |
int total_physical_memeory = int.Parse(info["TotalVisibleMemorySize"].ToString()); | |
int free_physical_memeory = int.Parse(info["FreePhysicalMemory"].ToString()); | |
int remmain_physical_memory = total_physical_memeory - free_physical_memeory; | |
Console.WriteLine("Memory Usage Percent = {0} %", 100 * remmain_physical_memory / total_physical_memeory); | |
} | |
ManagementClass cls2 = new ManagementClass("Win32_OperatingSystem"); | |
ManagementObjectCollection instances = cls2.GetInstances(); | |
// | |
StringBuilder str = new StringBuilder(); | |
foreach (ManagementObject instan in instances) | |
{ | |
foreach (PropertyData prop in instan.Properties) | |
{ | |
str.Append(string.Format("{0} : {1}", prop.Name, prop.Value)); | |
str.Append(Environment.NewLine); | |
} | |
} | |
Console.WriteLine(str); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment