One solution I used for this to grab machine diagnostics previously was to use DLLImport.
See P-Invoke
Hope this helps
Pete
In answer to your comment
When using DLL import you have to declare the function wrapper yourself. In the code below you can see the public static extern void which is saying to the compiler that it is an external call to a function called GlobalMemoryStatus which is located in the DLLImported kernel32.dll. The MemoryStatus struct which is an output parameter of the functionis populated inside the kernel32 dll and is returned back fully populated.
Copy this into your code and read the comments they should help you to understand it.
/// <summary>
/// Populates a memory status struct with the machines current memory status.
/// </summary>
/// <param name="stat">The status struct to be populated.</param>
[DllImport("kernel32.dll")]
public static extern void GlobalMemoryStatus(out MemoryStatus stat);
/// <summary>
/// The memory status struct is populated by the GlobalMemoryStatus external dll call to Kernal32.dll.
/// </summary>
public struct MemoryStatus
{
public uint Length;
public uint MemoryLoad;
public uint TotalPhysical;
public uint AvailablePhysical;
public uint TotalPageFile;
public uint AvailablePageFile;
public uint TotalVirtual;
public uint AvailableVirtual;
}
// copy the guts of this method and add it to your own method.
public void InspectMemoryStatus()
{
MemoryStatus status = new MemoryStatus();
GlobalMemoryStatus(out status);
Debug.WriteLine(status.TotalVirtual);
}
This should allow you to get the memory diagnostics of the machine.