Andrew J. Brehm
Andrew J. Brehm

Reputation: 4768

WMI Win32_OperatingSystem OSArchitecture field causes exception

I am trying to get information on the version of Windows installed from WMI. Most fields work. I can get the operating system "Name" as well as the "Version", both are fields of the Win32_OperatingSystem object I have.

But another field "OSArchitecture" generates an exception ("Not found").

    strScope = "\\" + strServer + "\root\CIMV2"
    searcher = New ManagementObjectSearcher(strScope, "SELECT * FROM Win32_OperatingSystem")

    For Each mo In searcher.Get

        strOSName = mo("Name")
        strOSVersion = mo("Version")
        strOSArchitecture = mo("OSArchitecture")
        strStatus = mo("Status")
        strLastBoot = mo("LastBootUpTime")

    Next

The documentation says that the field ought to exist and is a String:

http://msdn.microsoft.com/en-us/library/aa394239(VS.85).aspx

Any ideas?

Upvotes: 0

Views: 3530

Answers (2)

paxdiablo
paxdiablo

Reputation: 881633

Your original question had the line:

strOSArchitecture = mo("Architecture")

which should have been:

strOSArchitecture = mo("OSArchitecture")

Now that you've confirmed that was a simple typo in the question (not your actual code), the other likelihood is that you are running on either Server 2003, 2000, NT4, XP or Me/98/95, where the documentation lists the OSArchitecture key as unavailable?

Upvotes: 1

gimel
gimel

Reputation: 86372

To view a current (runtime) list of available properties, walk the Properties attribute. In a console application, it looks like:

For Each mo In searcher.Get
    Console.WriteLine("..." + mo.Properties.Count.ToString() + " properties")
    For Each prop In mo.Properties
        Console.WriteLine(prop.Name)
    Next
    '...

On my XP installation, no OSArchitecture appears in the 61 property names listed.

Upvotes: 1

Related Questions