Reputation: 29
I'm, unable to retrieve the PC model in VB6, the property I request from the query returns empty. I try to emulate the result of this CMD command.
wmic computersystem get model
This is the code I try to use. (I added Microsoft WMI scripting lib 1.2 as a reference in the project).
Function wmiInfo() As String
Dim List
Dim Msg
Dim Object
On Local Error Resume Next
Set List = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_BaseBoard")
For Each Object In List
Msg = Msg & "Motherboard Serial Number: " & Object.Model & vbCrLf
Next
MsgBox Msg
end function
I expect the function to retrieve just a string with the model of the PC something like "Optiplex 790" (it is what the cmd command returns). Any help is greatly appreciated.
(OS Windows 7)
Upvotes: 1
Views: 483
Reputation: 29
I found the issue. I was requesting the wrong class. Win32_computerSystem has the property I'm looking for.
Function wmiProcessorInfo() As String
Dim msg As String
Dim cpuSet As SWbemObjectSet
Dim cpu As SWbemObject
Dim itmx As ListItem
On Local Error Resume Next
Set cpuSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_ComputerSystem")
For Each cpu In cpuSet
msg = cpu.Model
Next
MsgBox msg
End Function
Upvotes: 1