' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential)> _
Public Structure MEMORYSTATUS
    Public dwLength As Integer
    Public dwMemoryLoad As Integer
    Public dwTotalPhys As Integer
    Public dwAvailPhys As Integer
    Public dwTotalPageFile As Integer
    Public dwAvailPageFile As Integer
    Public dwTotalVirtual As Integer
    Public dwAvailVirtual As Integer
End Structure 

Public Class MainClass

    <DllImport("kernel32.dll")> _
    Private Shared Sub GlobalMemoryStatus(ByRef lpBuffer As MEMORYSTATUS)
    End Sub
    Public Shared Sub Main(ByVal args As String())
        Dim ms As MEMORYSTATUS = New MEMORYSTATUS
        GlobalMemoryStatus(ms)
        Console.WriteLine("Used  = " & (ms.dwTotalPhys - ms.dwAvailPhys))
        Console.WriteLine("Free  = " & ms.dwAvailPhys)
        Console.WriteLine("Total = " & ms.dwTotalPhys)
    End Sub
End Class 
