2012-06-20 14 views
5

Il contatore perfmon sta usando nomi diversi NIC confronta con ipconfig/all e c chiamata # sistema, come potete vedere qui sotto (questo è da ipconfig/all)C contatore # prestazioni e il nome nic

Ethernet adapter HHHH:  

    Connection-specific DNS Suffix . : 

    Description . . . . . . . . . . . : HP NC364T PCIe Quad Port Gigabit Server Adapter #3 
    Physical Address. . . . . . . . . : 00-1F-29-0D-26-59 
    DHCP Enabled. . . . . . . . . . . : No 
    Autoconfiguration Enabled . . . . : Yes 
    IPv4 Address. . . . . . . . . . . : 166.49.47.10(Preferred) 
    Subnet Mask . . . . . . . . . . . : 255.255.255.240 
    Default Gateway . . . . . . . . . : 
    NetBIOS over Tcpip. . . . . . . . : Disabled 
using System.Net.NetworkInformation; 
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); 

Ottengo HP NC364T PCIe Quad Port Gigabit Server Adapter #3. Esattamente come ipconfig. MA il perfmon utilizza HP NC364T PCIe Quad Port Gigabit Server Adapter _3 (trattino basso anziché hash). Devo usare una chiamata diversa per ottenere lo stesso identico contatore di quello che ha il perfmon? Se è così, che cosa è?

+0

Si ottiene '" HP NC364T PCIe Quad Port Gigabit Server Adapter # 3 "utilizzando anche WMI – GETah

risposta

1

Personalmente utilizzerei il registro per elencare i dispositivi di rete in modo nativo. Ci sono molti modi per recuperare le informazioni, ma non tutti i modi mostrano le informazioni come fa il sistema. Un esempio di codice possibile potrebbe essere simile a questo (non completamente gestito da errori). Funziona per me su Windows Vista 32/64 bit e 7. È un po 'diverso dalla classe NET, ma pensa che funzioni allo stesso modo. Lo spazio dei nomi "using Microsoft.Win32" deve essere aggiunto per eseguire il codice.

private void button1_Click(object sender, EventArgs e) 
    { 
     ListPCIDevices(false, listBox1); 
    } 

    public static void ListPCIDevices(bool ListOnlyNetworkDevices, ListBox LB) 
    { 
     string NetKey = @"SYSTEM\ControlSet001\Enum\PCI"; 
     using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(NetKey)) 
     { 
      foreach (string skName in rk.GetSubKeyNames()) 
      { 
       using (RegistryKey sk = rk.OpenSubKey(skName)) 
       { 

        foreach (string skSubName in sk.GetSubKeyNames()) 
        { 

         using (RegistryKey ssk = sk.OpenSubKey(skSubName)) 
         { 

          object ItemName = ssk.GetValue("DeviceDesc"); 
          object ItemCat = ssk.GetValue("Class"); 
          if (ItemCat == null) { ItemCat = "Unknown"; } 

          if ((ItemName != null) && ((ItemCat.ToString() == "Net")||(!ListOnlyNetworkDevices))) 
          { 
           LB.Items.Add(ItemName.ToString().Split(';')[1]); 
          } 

         } 
        } 
       } 
      } 
     } 
    } 
Problemi correlati