WMI Win32_OperatingSystem OSArchitecture 字段导致异常

发布于 2024-08-26 02:02:44 字数 768 浏览 0 评论 0原文

我正在尝试从 WMI 获取有关安装的 Windows 版本的信息。大多数领域都有效。我可以获得操作系统“名称”和“版本”,两者都是我拥有的 Win32_OperatingSystem 对象的字段。

但另一个字段“OSArchitecture”生成异常(“未找到”)。

    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

该文档说该字段应该存在并且是一个字符串:

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

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀子花开つ 2024-09-02 02:02:44

您最初的问题有这样一行:

strOSArchitecture = mo("Architecture")

应该是:

strOSArchitecture = mo("OSArchitecture")

现在您已经确认这是问题中的一个简单拼写错误(不是您的实际代码),另一种可能性是您正在服务器 2003、2000、NT4、 XP 或 Me/98/95,其中文档将 OSArchitecture 键列为不可用?

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?

不疑不惑不回忆 2024-09-02 02:02:44

要查看可用属性的当前(运行时)列表,请查看 Properties 属性。
在控制台应用程序中,它看起来像:

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

在我的 XP 安装中,列出的 61 个属性名称中没有出现 OSArchitecture

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文