Search this blog

Monday, June 1, 2009

Find Ram Size thru C#

Use the following Code Snippet to retrieve the active size of RAM in Different Units

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Management;

using System.Management.Instrumentation;


namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

ManagementObjectSearcher Search = new ManagementObjectSearcher("Select * From Win32_ComputerSystem");

foreach (ManagementObject Mobject in Search.Get())

{

double Ram_Bytes = (Convert.ToDouble(Mobject["TotalPhysicalMemory"]));

Console.WriteLine("RAM Size in Bytes: {0}", Ram_Bytes);

Console.WriteLine("RAM Size in Kilo Bytes: {0}", Ram_Bytes / 1024);

Console.WriteLine("RAM Size in Mega Bytes: {0}", Ram_Bytes / 1048576);

Console.WriteLine("RAM Size in Giga Bytes: {0}", Ram_Bytes / 1073741824);

}

Console.ReadLine();

}

}

}

2 comments: