如何通过Excel / Access vba检查物理内存(RAM)DDR类型?

时间:2018-11-24 13:10:10

标签: excel vba excel-vba

是否可以通过Excel / Access VBA获取诸如DDR3 or DDR4之类的物理内存DDR信息。我的下面的子例程给我有关物理内存的详细信息,但不提供任何DDR信息。

Sub RAMDetails()
Dim oWMISrvEx As Object
Dim oWMIObjSet As Object
Dim oWMIObjEx As Object
Dim oWMIProp As Object
Dim sWQL As String
Dim n

Dim sht As Worksheet

Set sht = ThisWorkbook.Sheets("Sheet1")

sWQL = "Select * From Win32_PhysicalMemory"


Set oWMISrvEx = GetObject("winmgmts:root/CIMV2")
Set oWMIObjSet = oWMISrvEx.ExecQuery(sWQL)
intRow = 2
strRow = Str(intRow)

sht.Range("A1").Value = "Name"
sht.Cells(1, 1).Font.Bold = True

sht.Range("B1").Value = "Value"
sht.Cells(1, 2).Font.Bold = True

For Each oWMIObjEx In oWMIObjSet
    For Each oWMIProp In oWMIObjEx.Properties_
        If Not IsNull(oWMIProp.Value) Then

            If IsArray(oWMIProp.Value) Then
                For n = LBound(oWMIProp.Value) To UBound(oWMIProp.Value)
                    Debug.Print oWMIProp.Name & "(" & n & ")", oWMIProp.Value(n)
                      sht.Range("A" & Trim(strRow)).Value = oWMIProp.Name
                        sht.Range("B" & Trim(strRow)).Value = oWMIProp.Value(n)
                        sht.Range("B" & Trim(strRow)).HorizontalAlignment = xlLeft
                       intRow = intRow + 1
                    strRow = Str(intRow)
                Next

                Else
                    sht.Range("A" & Trim(strRow)).Value = oWMIProp.Name
                       sht.Range("B" & Trim(strRow)).Value = oWMIProp.Value
                        sht.Range("B" & Trim(strRow)).HorizontalAlignment = xlLeft
                       intRow = intRow + 1
                    strRow = Str(intRow)
            End If

        End If
    Next
Next
End Sub

0 个答案:

没有答案