VBForums >
.NET >
C# > [RESOLVED] [1.0/1.1] Retrieving the total amount of RAM from a computer
Click to See Complete Forum and Search --> : [RESOLVED] [1.0/1.1] Retrieving the total amount of RAM from a computer
JenniferBabe
Jun 5th, 2006, 11:12 AM
Hi. Does anyone know how to retrieve the amount of RAM in megabytes from a computer?
Hack
Jun 5th, 2006, 11:26 AM
This (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/globalmemorystatus.asp) might help.
JenniferBabe
Jun 5th, 2006, 12:25 PM
Thanks Hack. This is the solution:
using System.Runtime.InteropServices; // To use Dll import.
....
[DllImport("kernel32.dll")]
public static extern void GlobalMemoryStatus(out MemoryStatus stat);
public struct MemoryStatus
{
public uint Length; //Length of struct
public uint MemoryLoad; //Value from 0-100 represents memory usage
public uint TotalPhysical; // The total RAM.
public uint AvailablePhysical; // The Available RAM.
public uint TotalPageFile;
public uint AvailablePageFile;
public uint TotalVirtual;
public uint AvailableVirtual;
}
......
MemoryStatus MemStat = new MemoryStatus();
GlobalMemoryStatus(out MemStat);
......
Console.WriteLine(MemStat.TotalPhysical/1024/1024.ToString());
...// To access available RAM, MemStat.AvailablePhysical
Jennifer :thumb:
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.