Results 1 to 5 of 5

Thread: Get All RAM infos using WMI

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2012
    Posts
    61

    Get All RAM infos using WMI

    Hi.

    I've got the following code that Outputs the information about the RAM modules into Textboxes.


    Code:
            Try
                Dim k As System.Management.ManagementObject
                'Dim search_Memory As New System.Management.ManagementObjectSearcher("Select * from CIM_Memory")
                Dim search_Memory As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory")
    
    
                For Each k In search_Memory.Get()
    
                    TextBoxX1.Text = k("BankLabel").ToString     'Gives the Slot Number of the RAM in the First Slot 
                    TextBoxX2.Text = k("Capacity").ToString     'Gives capacity of only one RAM module 
                    TextBoxX3.Text = k("PartNumber").ToString     ' Shows part number for only one RAM module
    
                Next
    
            Catch ex As Exception
                MessageBox.Show("Couldn't Load Certain Memory Information", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

    As you can see from the Comments in my code as well..
    I only get the Information about a Single RAM module..

    How would I go about to get information for all of the RAM Modules in separate Text boxes ?

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Get All RAM infos using WMI

    Needing an unknown number of controls can be a headache to manage at runtime, why not just do it the way apps like CPU-Z and others do it and only show info for one bank at a time, for example CPU-Z uses a combobox to select which bank of ram to view, that should be easy to implement...

    Code:
    Public Class Form1
    
        Private Class RamData
            Public BankLabel As String
            Public Capacity As String
            Public PartNumber As String
            Public Sub New(banklabel As String, capacity As String, partNumber As String)
                Me.BankLabel = banklabel
                Me.Capacity = capacity
                Me.PartNumber = partNumber
            End Sub
        End Class
    
        Private memoryInfo As New List(Of RamData)
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Try
                Dim k As System.Management.ManagementObject
                Dim search_Memory As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory")
                For Each k In search_Memory.Get()
                    ' add bank name to combo
                    ComboBox1.Items.Add(k("BankLabel").ToString)
                    ' add memory data to our list
                    memoryInfo.Add(New RamData(k("BankLabel").ToString, k("Capacity").ToString, k("PartNumber").ToString))
                Next
            Catch ex As Exception
                MessageBox.Show("Couldn't Load Certain Memory Information", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
    
        End Sub
    
        ' show data for selected bank
        Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            Dim index As Integer = ComboBox1.SelectedIndex
            If index > -1 Then
                TextBox1.Text = memoryInfo(index).BankLabel
                TextBox2.Text = memoryInfo(index).Capacity
                TextBox3.Text = memoryInfo(index).PartNumber
            End If
        End Sub
    End Class

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2012
    Posts
    61

    Re: Get All RAM infos using WMI

    I actually tried that as well.. but i couldn't figure out how to call the details for the appropriate (selected) bank.

    Any ideas?

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Get All RAM infos using WMI

    Quote Originally Posted by TheThinker View Post
    I actually tried that as well.. but i couldn't figure out how to call the details for the appropriate (selected) bank.

    Any ideas?
    In the code I posted above the bank name is added to a combo and all the memory data is added to the list of memoryInfo, So now when you select the bank name in the combo you can just use the combo index as a pointer to the memorryInfo list and display the data in a textbox, lable or whatever.

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2012
    Posts
    61

    Re: Get All RAM infos using WMI

    Oh. Sorry.. i didn't see that..
    I'll try it out asap and will let you know how it goes.

    Thanks man..

    [EDIT:
    Works Perfectly.. Just what I was looking to do...
    I'll be sure to include your name in the Special Thanks Section when I release my App which is Called "TINY TOOLBOX"
    Thanks a ton.. ]
    Last edited by TheThinker; Nov 30th, 2012 at 01:49 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width