开发者

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?


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜