2012-06-20 25 views
5

perfmon sayacı ipconfig farklı NIC isimler karşılaştırın kullanıyor/tüm ve (/ bu ipconfig dan tümü) aşağıda görebileceğiniz gibi C# sistem çağrısıC# performans sayacı ve nic adı

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(); 

HP NC364T PCIe Quad Port Gigabit Server Adapter #3'u alırım. Tam olarak ipconfig ile aynı. BUT perfmon HP NC364T PCIe Quad Port Gigabit Server Adapter _3 (hash yerine alt çizgi) kullanmaktadır. Perfone ne ile aynı tam sayaç adını almak için farklı bir çağrı kullanmak zorunda mıyım? Eğer öyleyse, nedir?

+0

WMI kullanarak "" HP NC364T PCIe Dört Bağlantı Noktalı Gigabit Sunucu Bağdaştırıcısı # 3 "ü alırsınız – GETah

cevap

1

Kişisel olarak Ağ aygıtlarını yerel olarak listelemek için kayıt defterini kullanırdım. Bilgiyi almanın birçok farklı yolu vardır, ancak tüm yollar sistemde olduğu gibi bilgisini görüntülemez. Olası bir kod örneği şöyle görünebilir (tam olarak hata değil). Windows Vista 32/64 bit ve 7 üzerinde çalışıyor. NET sınıfından oldukça farklı, ama aynı şekilde olduğunu düşünüyorum. Kodu çalıştırmak için "Microsoft.Win32 kullanarak" Ad alanı eklenmelidir.

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]); 
          } 

         } 
        } 
       } 
      } 
     } 
    }