使用WMI服务 [英] Working With WMI Services

查看:85
本文介绍了使用WMI服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在项目中使用WMI完成了一些示例代码,以从变量(Win32_ComputerSystem)等中检索某些信息.一些地区虽然有各种各样的清单.例如,这将给我计算机的名称.

Hello I''v done a few example codes in my Project using WMI to retrive certain information from variables such as (Win32_ComputerSystem) and so forth. Some area though have a variety of list. For example this would give me the name of the computer.

Dim strComputer = "."
Dim objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    On Error Resume Next
        Dim objItem
Dim SystemProductInfo = objWMIService.ExecQuery("Select * from _ Win32_ComputerSystemProduct")
         

For Each objItem In SystemProductInfo
            SystemInfo.LabelComputerModel.Text = objItem.Version
            SystemInfo.TBManufacturer.Text = objItem.Vendor
            SystemInfo.TBModel.Text = objItem.Name
        Next



但是,如果我玩其他变量,例如从Win32_PhysicalMemory中选择*",
并尝试链接到该链接以获取其中列出的Ram的名称或大小.因为我的计算机中有两根RAM,所以有两个信息集,它们将共享相同的变量,例如objItem.Name和objItem.Size.有没有一种方法可以使For Each语句同时循环两个类别,并从安装的Rams的名称和大小信息中获取信息.因为到目前为止,当我尝试它时,我仅获得第一只公羊棍"的信息,而不是下一头.

更大的图片:我正在使用此代码来开发一个小应用程序,以告诉安装了什么内存,主板可以容纳的最大容量,剩余的插槽数以及使用的插槽数.如果WMI是执行上述任何操作的错误方法,那么向正确方向提供的任何帮助都将是不错的选择.

谢谢



But if I play with other variables such as "select * from Win32_PhysicalMemory"
and try to link to that to get Name or Size of the Ram listed in there. Because I have two sticks of ram in the computer, there is two collection of info that will share the same variables like objItem.Name and objItem.Size. Is there a way to make the For Each statement loop both categories and get the information from both information of name and size of the Rams Installed. Because when I tried it so far, I just get the information of the First Ram Stick, but not the next.

Bigger Pictures: I''m using this code to hopefully develop a little app that tells what ram is installed, the max your motherboard can take, how many slots are left, and how many slots are used. If WMI is the wrong way to do any of this, any help to the right direction would be nice.

Thanks

推荐答案

嘿.如果有人想知道,这里就是解决方案.一点时间,我一如既往地凭自己的想法来解决

Hey Me. Here the solution if anybody else wanted to know. A little bit of time, and as always I figure it out on my own lol

Sub GetRamInfo()
        Dim StrComputer = "."
        Dim objWMIService = GetObject("winmgmts:" & " _ {impersonationLevel=impersonate}!\\" & StrComputer & "\root\cimv2")
        
        Dim colQuickFixes = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory")

        For Each objQuickFix In colQuickFixes
            MsgBox("BankLabel: " & objQuickFix.BankLabel)
            MsgBox("PartNumber: " & objQuickFix.PartNumber)
        Next
    End Sub


这篇关于使用WMI服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆