Problem with Win32_OperatingSystem Class PLEASE HELP (1 Viewer)

Bilbo_Baggins_Esq

Registered User.
Local time
Today, 03:19
Joined
Jul 5, 2007
Messages
586
I need to get a list of all the Win32_OperatingSystem properties and their values on various different platforms.

I’ve done some reading and testing and afraid I’ve hit a brick wall.

Running Office 2010 (x86) on Win7 (x64)
I’m able to get the Key Property value for the instance, but then throw an automation error when I try to set an object using that Key Property.

Here is the code:
Code:
Sub GetSystemInfoTest()

Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim strComputer As String

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.InstancesOf("Win32_OperatingSystem")
    
For Each objItem In colItems        
        MsgBox objItem.name
        GetOperatingSystemInfo objItem.name
Next

    Set objWMIService = Nothing
    Set colItems = Nothing

End Sub

Sub GetOperatingSystemInfo(strKeyValue As String)

Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim strWMINamespace As String
Dim strComputer As String
Dim strWMIQuery As String

strComputer = "."
strWMINamespace = "\root\CIMV2"

strWMIQuery = ":Win32_OperatingSystem.Name='" & strKeyValue & "'"

[COLOR="Red"][B]Set objWMIService = GetObject("winmgmts:\\" & strComputer & strWMINamespace & strWMIQuery)[/B][/COLOR]
For Each objItem In objWMIService.Properties_
    Debug.Print objItem.name & ": " & objItem.Value
Next

Set objItem = Nothing
Set colItems = Nothing
Set objWMIService = Nothing

End Sub
It seems like it might be a syntax problem but I’ve tried several different combinations and no luck.

I’ve referenced this site for the “GetOperatingSystemInfo”:
http://accesstips.wordpress.com/200...formation-using-microsoft-access-vba-and-wmi/

Any help will be GREATLY appreciated
 

Old Man Devin

Consul Of Code
Local time
Today, 09:19
Joined
Jan 10, 2014
Messages
183
Could be because strComputer is "." and so the "winmgmts\\.stuff" isn't a valid path (normally paths like that don't have dots in them)? Not really sure, have never used these functions myself, but that would be my guess.
 

pr2-eugin

Super Moderator
Local time
Today, 09:19
Joined
Nov 30, 2011
Messages
8,494
I am not completely sure how the Code works, and I do not have the time right now to go through the code either, but a simple glace, I can see you have 64 bit version of Windows, but the Code is aimed at 32 bit machine. So try changing it to Win64?
Code:
strWMIQuery = ":Win[COLOR=Red][B]64[/B][/COLOR]_OperatingSystem.Name='" & strKeyValue & "'"
Again, the above is just a suggestion. Not sure if it will work !
 

Bilbo_Baggins_Esq

Registered User.
Local time
Today, 03:19
Joined
Jul 5, 2007
Messages
586
Thanks guys, but you're off track.

If you look at the preceeding sub, it works just fine with the "." and "Win32_OperatingSystem" to pull the instance name.

I also successfully use Win32_Processes in other functions to capture all the processes.

PLEASE OTHERS, if you have some real ideas, hop in, the above two posts are off track
 

JHB

Have been here a while
Local time
Today, 10:19
Joined
Jun 17, 2012
Messages
7,732
I've tested you code on a computer with Windows XP and here the code run ok, but looking on the value which comes out, you get the same values if you take it from the objItem Properties_!
Try the code below and see if it gives you what you expected.

Code:
Sub GetSystemInfoTest()
On Error GoTo errorHandling
Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim objItem1 As Object, x As Integer
Dim strComputer As String

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.InstancesOf("Win32_OperatingSystem")
    
For Each objItem In colItems
    x = 1
    For Each objItem1 In objItem.Properties_
        Debug.Print objItem1.Name & ": " & objItem1.Value
        x = x + 1
    Next

Next
Exit Sub

errorHandling:
  MsgBox (Err.Number & " " & Err.Description & " in item =" & x)
  Resume Next
End Sub
 

Bilbo_Baggins_Esq

Registered User.
Local time
Today, 03:19
Joined
Jul 5, 2007
Messages
586
THANKS JHB, it does indeed run!

I had tried that same exact set of code prior to posting here, except I left off the _ after .Properties and it kept throwing "Object doesn't support property or method.

d'OH!

Thanks again mate!
 

JHB

Have been here a while
Local time
Today, 10:19
Joined
Jun 17, 2012
Messages
7,732
You're welcome, luck with your project. :)
 

Users who are viewing this thread

Top Bottom