Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Strict On
- Option Explicit On
- Imports System.Math
- Imports System.Management
- Imports System.Runtime.InteropServices
- Public Class Form1
- #Region " API "
- Private memoryInfo As MEMORYSTATUSEX = New MEMORYSTATUSEX
- Private Declare Auto Sub GlobalMemoryStatusEx Lib "kernel32" (<[In](), Out()> lpBuffer As MEMORYSTATUSEX)
- #End Region
- #Region " Variables "
- Private mullTotalRAM As ULong
- #End Region
- #Region " Form Events "
- Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
- ' set title
- Me.Text = My.Application.Info.Title & " " & My.Application.Info.Version.Major.ToString & "." & _
- My.Application.Info.Version.Minor.ToString
- Application.DoEvents()
- GetMemoryInfo()
- Timer1.Enabled = True
- End Sub
- #End Region
- #Region " Information Gathering and Display "
- Private Sub GetMemoryInfo()
- System.Windows.Forms.Application.DoEvents()
- GlobalMemoryStatusEx(memoryInfo)
- mullTotalRAM = memoryInfo.ullTotalPhys
- txtRAM.Text = FormatBytes(mullTotalRAM)
- End Sub
- #End Region
- #Region " Update Timer "
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- GetMemoryInfo()
- Application.DoEvents()
- End Sub
- #End Region
- #Region " Formatting Routines "
- Private Function FormatBytes(ByVal ullBytes As ULong) As String
- Dim dblTemp As Double
- Try
- Select Case ullBytes
- Case Is >= 1073741824 'GB
- dblTemp = CDbl(ullBytes / 1073741824)
- Return FormatNumber(dblTemp, 2) & " GB"
- Case 1048576 To 1073741823
- dblTemp = CDbl(ullBytes / 1048576) 'MB
- Return FormatNumber(dblTemp, 0) & " MB"
- Case 1024 To 1048575
- dblTemp = CDbl(ullBytes / 1024) 'KB
- Return FormatNumber(dblTemp, 0) & " KB"
- Case 0 To 1023
- dblTemp = ullBytes ' bytes
- Return FormatNumber(dblTemp, 0) & " bytes"
- Case Else
- Return ""
- End Select
- Catch
- Return ""
- End Try
- End Function
- #End Region
- End Class
- <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
- Public Class MEMORYSTATUSEX
- ''' <summary>
- ''' Initializes a new instance of the <see cref="T:MEMORYSTATUSEX" /> class.
- ''' </summary>
- Public Sub New()
- Me.dwLength = CType(Marshal.SizeOf(GetType(MEMORYSTATUSEX)), UInt32)
- End Sub
- ' Fields
- ''' <summary>
- ''' Size of the structure, in bytes. You must set this member before calling GlobalMemoryStatusEx.
- ''' </summary>
- Public dwLength As UInt32
- ''' <summary>
- ''' Number between 0 and 100 that specifies the approximate percentage of physical memory that is in use (0 indicates no memory use and 100 indicates full memory use).
- ''' </summary>
- Public dwMemoryLoad As UInt32
- ''' <summary>
- ''' Total size of physical memory, in bytes.
- ''' </summary>
- Public ullTotalPhys As UInt64
- ''' <summary>
- ''' Size of physical memory available, in bytes.
- ''' </summary>
- Public ullAvailPhys As UInt64
- ''' <summary>
- ''' Size of the committed memory limit, in bytes. This is physical memory plus the size of the page file, minus a small overhead.
- ''' </summary>
- Public ullTotalPageFile As UInt64
- ''' <summary>
- ''' Size of available memory to commit, in bytes. The limit is ullTotalPageFile.
- ''' </summary>
- Public ullAvailPageFile As UInt64
- ''' <summary>
- ''' Total size of the user mode portion of the virtual address space of the calling process, in bytes.
- ''' </summary>
- Public ullTotalVirtual As UInt64
- ''' <summary>
- ''' Size of unreserved and uncommitted memory in the user mode portion of the virtual address space of the calling process, in bytes.
- ''' </summary>
- Public ullAvailVirtual As UInt64
- ''' <summary>
- ''' Size of unreserved and uncommitted memory in the extended portion of the virtual address space of the calling process, in bytes.
- ''' </summary>
- Public ullAvailExtendedVirtual As UInt64
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement