Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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.

VB
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


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
Posted
Comments
Sandeep Mewara 10-Jun-12 5:34am    
Well presented, good question. 5!

1 solution

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

VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900