MSAccess-总计和可用内存统计信息?

时间:2018-11-05 18:15:03

标签: vba ms-access

我目前正在使用以下内容来报告使用我的MSAccess应用程序的各种客户端的总内存。我看到的用户范围很广:2GB至32GB。

除了总内存,我想也可以报告可用内存。有任何指针/ API引用吗?

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

1 个答案:

答案 0 :(得分:2)

看看这段与您的代码非常相似的代码:

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

我在这里找到它 https://social.technet.microsoft.com/Forums/office/en-US/517ae39d-b300-4bdd-8503-9f8699cb4e9d 并对VBA进行了一些修改。