Dear All,
such a long time from my last post but hopefully I'm here again to find some help.
This time I'm trying to get system info via WMI with Excel VBA and I wanted to ask some advices.
My goal is to list all values for each property of a give WMI.Win32_xxxx class.
My question is about how to get all the keys for all properties listed without actually write in my code all properties' names.
I explain myself better, I have the code below:
Function GetOSInfo(strClassName) As String
Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim strComputer As String
Dim strOSName As String
Dim strWQL As String
strComputer = "."
strWQL = "SELECT * FROM " & strClassName
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery(strWQL)
For Each objItem In colItems
' Get the Value of the Properties
' START OF CODE PART I WANT TO ENHANCE
Debug.Print objItem.Name
Debug.Print objItem.BootDevice
Debug.Print objItem.BuildNumber
Debug.Print objItem.Caption
Debug.Print objItem.CodeSet
Debug.Print objItem.CountryCode
Debug.Print objItem.CreationClassName
Debug.Print objItem.CSDVersion
Debug.Print objItem.CSName
Debug.Print objItem.CurrentTimeZone
Debug.Print objItem.DataExecutionPrevention_32BitApplications
Debug.Print objItem.DataExecutionPrevention_Available
Debug.Print objItem.DataExecutionPrevention_Drivers
Debug.Print objItem.DataExecutionPrevention_SupportPolicy
Debug.Print objItem.Debug
Debug.Print objItem.Description
Debug.Print objItem.Distributed
Debug.Print objItem.EncryptionLevel
Debug.Print objItem.ForegroundApplicationBoost
Debug.Print objItem.FreePhysicalMemory
'Debug.Print objItem.FreeSpaceInPaginFiles
Debug.Print objItem.FreeVirtualMemory
Debug.Print objItem.InstallDate
Debug.Print objItem.LargeSystemCache
Debug.Print objItem.LastBootUpTime
Debug.Print objItem.LocalDateTime
Debug.Print objItem.Locale
Debug.Print objItem.Manufacturer
Debug.Print objItem.MaxNumberOfProcesses
[...]
' END OF CODE PART I WANT TO ENHANCE
Next
Set objItem = Nothing
Set colItems = Nothing
Set objWMIService = Nothing
End Function
Sub GetData()
GetOSInfo("Win32_OperatingSystem")
End Sub
It's a simple code in which I call a function passing the class I want to list the properties' values from.
Since the class Win32_OperatingSystem contains 63 properties, I'm wondering if is there a way to loop through all of them in order to get those data without writing all the names of the properties.
I mean, something like:
For Each objItem In colItems
For i=1 to colItems.Item 1.Properties_.Count
Debug.Print colItems.Item[1]. Properties_[i].Value
Next
Next
Unluckily this code doesn't work because I'm not referencing correctly the structure of the class.
Any help would be highly appreciated. 
regards,
PP
Bookmarks