'Exemple d'appel :
' Dim ColResult As Collection = ListPhysicalMemory()
' For i As Integer = 1 To ColResult.Count
' Console.WriteLine("Slot " & i & " ---> " & ColResult.Item(i) & " Octets")
' Next
'Function :
Private Function ListPhysicalMemory() As Collection
Dim Resultat As New Collection
Dim myScop As New Management.ManagementScope("\\" & Environment.MachineName & "\root\cimv2")
Dim oQuer As New Management.SelectQuery("SELECT * FROM Win32_PhysicalMemory")
Dim oResult As New Management.ManagementObjectSearcher(myScop, oQuer)
Dim oIte As Management.ManagementObject
Dim oPropert As Management.PropertyData
Dim StrFinal As String = Nothing
Dim Idx As Integer = 0
Try
Resultat.Clear()
For Each oIte In oResult.Get()
For Each oPropert In oIte.Properties
StrFinal &= oPropert.Name & " ---> "
If Not oPropert.Value Is Nothing Then StrFinal &= oPropert.Value
StrFinal &= vbCrLf
If Not oPropert.Value Is Nothing AndAlso oPropert.Name = "Capacity" Then
Dim Valeur As String = oPropert.Value
Resultat.Add(oPropert.Value, "Slot " & Idx)
End If
Next
Idx += 1
Next
Catch ex As Exception
MessageBox.Show(ex.Message & vbCrLf & ex.StackTrace, "Erreur", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Temp & "\IRam.txt", _
StrFinal, False, System.Text.Encoding.Default)
Process.Start(My.Computer.FileSystem.SpecialDirectories.Temp & "\IRam.txt")
Return Resultat
End Function