C# - RAM informations

By , 7/30/2013
(1 ratings)
Informations about the RAM can be retrieved via different ways. For example:
x) WMI queries
x) PerformanceCounter class
x) API calls using P/Invoke

But there is also a very easy way by using the ComputerInfo class located in VisualBasic.Devices.

Author: Günther Foidl, translation by Michael List
Translate to VB
using System;
using Microsoft.VisualBasic.Devices; // Add reference!

namespace RAM
{
	class Program
	{
		static void Main()
		{
			ComputerInfo computerInfo = new ComputerInfo();
			ulong availableRAM = computerInfo.AvailablePhysicalMemory;
			ulong totalRAM = computerInfo.TotalPhysicalMemory;

			Console.WriteLine("Available:\t {0} Bytes \t= {1} MB",
				availableRAM,
				availableRAM / (1024 * 1024));
			Console.WriteLine("Total:\t\t {0} Bytes \t= {1} MB",
				totalRAM,
				totalRAM / (1024 * 1024));
			Console.ReadKey();
		}
	}
}

Comments

 

Log in, to comment!