2008-12-04 3 views

Répondre

3

Le System.Management Namespace donne accès à un ensemble riche d'événements d'information de gestion et de gestion sur le système, les appareils et les applications instrumentés à l'infrastructure Windows Management Instrumentation (WMI).

La classe Win32 Processor WMI représente un périphérique capable d'interpréter une séquence d'instructions sur un ordinateur fonctionnant sous un système d'exploitation Windows. Sur un ordinateur multiprocesseur, une instance de la classe Win32_Processor existe pour chaque processeur. La classe comprend un champ Processor family type, codant des choses comme Famille de processeurs AMD Opteron. Un exemple de C# issuing WMI query se trouve à la fin de la page.

11

S'il vous plaît noter que ceci est de VS2003:

using(ManagementObjectSearcher win32Proc = new ManagementObjectSearcher("select * from Win32_Processor"),   
    win32CompSys = new ManagementObjectSearcher("select * from Win32_ComputerSystem"), 
     win32Memory = new ManagementObjectSearcher("select * from Win32_PhysicalMemory")) 
      { 
       foreach (ManagementObject obj in win32Proc.Get()) 
       { 
        clockSpeed = obj["CurrentClockSpeed"].ToString(); 
        procName = obj["Name"].ToString(); 
        manufacturer = obj["Manufacturer"].ToString(); 
        version = obj["Version"].ToString(); 
       } 
+3

Note que "CurrentClockSpeed" n'est pas la propriété que vous devriez regarder pour déterminer MHz (Windows peut désactiver la plupart des processeurs modernes lorsque l'utilisation est faible, afin d'économiser de l'énergie). Au lieu de cela, vous devriez regarder "MaxClockSpeed" - qui est la vitesse d'horloge maximale que Windows peut faire fonctionner le processeur à. – BrainSlugs83

0

Ce code obtenir des propriétés CPU

Imports System.Management 



    Private Sub InsertInfo() 
       lstView.Items.Clear() 

       Dim searcher As New ManagementObjectSearcher("select * from Win32_Processor") 

       Try 
        For Each share As ManagementObject In searcher.Get() 

         Dim grp As ListViewGroup 
         Try 
          grp = lstView.Groups.Add(share("Name").ToString(), share("Name").ToString()) 
         Catch 
          grp = lstView.Groups.Add(share.ToString(), share.ToString()) 
         End Try 

         If share.Properties.Count <= 0 Then 
          MessageBox.Show("No Information Available", "No Info", MessageBoxButtons.OK, MessageBoxIcon.Information) 
          Return 
         End If 


         For Each PC As PropertyData In share.Properties 

          Dim item As New ListViewItem(grp) 
          If lstView.Items.Count Mod 2 <> 0 Then 
           item.BackColor = Color.White 
          Else 
           item.BackColor = Color.WhiteSmoke 
          End If 

          item.Text = PC.Name 

          If PC.Value IsNot Nothing AndAlso PC.Value.ToString().Length > 0 Then 
           Select Case PC.Value.GetType().ToString() 
            Case "System.String[]" 
             Dim str As String() = DirectCast(PC.Value, String()) 

             Dim str2 As String = "" 
             For Each st As String In str 
              str2 += st & " " 
             Next 

             item.SubItems.Add(str2) 

             Exit Select 
            Case "System.UInt16[]" 
             Dim shortData As UShort() = DirectCast(PC.Value, UShort()) 


             Dim tstr2 As String = "" 
             For Each st As UShort In shortData 
              tstr2 += st.ToString() & " " 
             Next 

             item.SubItems.Add(tstr2) 

             Exit Select 
            Case Else 

             item.SubItems.Add(PC.Value.ToString()) 
             Exit Select 
           End Select 
          Else 
           Continue For 
          End If 
          lstView.Items.Add(item) 
         Next 
        Next 


       Catch exp As Exception 
        MessageBox.Show("can't get data because of the followeing error " & vbLf & exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information) 
       End Try 


       End Sub 
Questions connexes