Les Snippets

Connexion

Quantifier la RAM de chaque slot

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 06/02/2007 00:47:11 et initié par PCPT [Liste]
Date de mise à jour : 03/03/2007 11:00:23
Vue : 5231
Catégorie(s) : Système, Divers
Langages dispo pour ce code :
- VB6, VBA
- VB 2005
- C# 1.x, C# 2.x



Langage : VB6 , VBA
Date ajout : 06/02/2007
Posté par PCPT [Liste]
Private Sub ListPhysicalMemory(ByRef aArray() As Double)
    On Local Error Resume Next
    Dim sComputerName As String, i As Integer
    sComputerName = Environ$("COMPUTERNAME")
    i = 1
    
    Dim WMI_Obj As Object, WMI_ObjProps As Object, ObjClsItem As  Object
    Set WMI_Obj = GetObject("winmgmts:\\" & sComputerName & "\root\cimv2")
    Set WMI_ObjProps = WMI_Obj.ExecQuery("Select * from Win32_PhysicalMemory", , 48)
    
    
    For Each ObjClsItem In WMI_ObjProps
        ReDim Preserve aArray(i)
        aArray(i) = ObjClsItem.Capacity
        i = i + 1
    Next ObjClsItem
    
    aArray(i) = 0
    For i = To UBound(aArray)
        aArray(0) = aArray(0) + aArray(i)
    Next i
    
    Set ObjClsItem = Nothing
    Set WMI_ObjProps = Nothing
    Set WMI_Obj = Nothing
End Sub

Remarque :
dimension 0 retourne la somme
les autres retournent la quantité de RAM sur le slot du même ID
Langage : VB 2005
Date ajout : 06/02/2007
Posté par surfzoid [Liste]
'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

Langage : C# 1.x , C# 2.x
Date ajout : 03/03/2007
Posté par Willi [Liste]
DateMAJ : 03/03/2007
public static string[] ListPhysicalMemory() 
{
     ManagementScope mscope = new ManagementScope(string.Format(@"\\{0}\root\cimv2", Environment.MachineName)); 
     ManagementObjectSearcher mos = new ManagementObjectSearcher(mscope, new ObjectQuery("SELECT * FROM Win32_PhysicalMemory"));

     StringBuilder szb = new StringBuilder();
     foreach (ManagementObject mo in mos.Get())
          szb.AppendFormat(@"{0}:{1};", mo.Properties["BankLabel"].Value, mo.Properties["Capacity"].Value);

     mos.Dispose();


     string szResult=szb.ToString().Trim();
     return szResult.Remove(szResult.Length - 1).Split(";".ToCharArray()); 
}

static void Main(string[] args) 
{
     System.Collections.IEnumerator ieret = ListPhysicalMemory().GetEnumerator();
     while (ieret.MoveNext()) 
     {
     Console.WriteLine(ieret.Current.ToString()); 
     }
}

}


Remarque :
Ajouter la directive
Using System.Management

Snippets en rapport avec : Wmi, Mémoire, Ram, Physique



Codes sources en rapport avec : Wmi, Mémoire, Ram, Physique

{Visual Basic, VB6, VB.NET, VB 2005} QUANTIFIER LA RAM DE CHAQUE SLOT
en plein tri, le nez dans de vieilles bécanes, pas facile de voir quelle barette fait combien.... i...

{Visual Basic, VB6, VB.NET, VB 2005} DES INFORMATIONS SUR VOS BARRETTES MÉMOIRES : SERIAL PRESENCE DETECT (SPD)
CE PROGRAMME NE FAIT QUE DE LA LECTURE CEPENDANT IL EST FOURNI SANS AUCUNE GARANTIE... Ce code pe...

{Visual Basic, VB6, VB.NET, VB 2005} MÉMOIRE PHYSIQUE, VIRTUELLE ET FICHIER D'ÉCHANGE
Utilistation de l'api globalmemorystatut, cette fonction retourne la mémoire totale disponible et ut...

{Visual Basic, VB6, VB.NET, VB 2005} TOUS SAVOIR SUR SA RAM OCX
Vous pouvez connaitre le Total de Ram en Octets et en Mega ou bien connaitre les pourcentage utliser...

{Visual Basic, VB6, VB.NET, VB 2005} LISTE DES PROCESSUS
Ce code va vous permettre de voir tout ce que votre RAM contient, les fenetre visible et non visible...

{C / C++ / C++.NET} [WMI][C++][DEV-C++] LECTURES D'INFORMATIONS AVEC WMI SOUS DEVCPP
Lecture d'informations WMI en C++ avec DEVC++. A voir: - plantage avec certains...

{Visual Basic, VB6, VB.NET, VB 2005} SIMULATEUR PHYSIQUE FINALZ
Il s'ajit d'un simulateur physique comme VBFrance n'a jamais connu. En effet au lieu de s'interress...

{PDA / PocketPC} LECTURE DES INFORMATIONS DE LA MÉMOIRE
Simple et sympa, Le code permet d'extraire les informations sur la mémoire du PDA entre autre: ...

{C# / C#.NET} SAVOIR L'ADRESSE PHYSIQUE (MAC) DES CARTES RÉSEAUX DE L'ORDINATEUR
Ce bout de code sert a chercher les adresses physiques (MAC) des cartes réseaux installées sur la ma...

{Visual Basic, VB6, VB.NET, VB 2005} UTILISATION DU MOTEUR 3D OGRE, DU MOTEUR PHYSIQUE NEWTON ET DES SCÈNES OFUSION
Bonjour Je vous propose un outil implémentant OGRE et NEWTON sous VB 2008. Pour ce faire, j'ai ut...