Reputation: 1359
I am currently using the following to report the total memory of the various clients using my MSAccess app. I am seeing a wide range of users: 2GB to 32GB.
In addition to total memory, I presume it is also possible to report available memory. Any pointers/API references, please?
Public Function SysMemory()
Dim oInstance
Dim colInstances
Dim dRam As Double
Set colInstances = GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_PhysicalMemory")
For Each oInstance In colInstances
dRam = dRam + oInstance.Capacity
Next
SysMemory = Int(dRam / 1024 / 1024 / 1000) & "GB"
End Function
Upvotes: 0
Views: 194
Reputation: 3465
Take a look at this code, very similar to yours:
Sub ShowFreeMemory()
Dim computerName As String
computerName = "."
Dim wmiService As Object
Set wmiService = GetObject("winmgmts:\\" & computerName & "\root\cimv2")
Dim items As Object
Set items = wmiService.ExecQuery("Select * from Win32_PerfFormattedData_PerfOS_Memory", , 48)
Dim item As Object
For Each item In items
Debug.Print "Available GB: " & Round(item.AvailableBytes / 1024 / 1024 / 1024, 3)
Next
End Sub
I found it here https://social.technet.microsoft.com/Forums/office/en-US/517ae39d-b300-4bdd-8503-9f8699cb4e9d and reworked it a bit for VBA.
Upvotes: 2