c#获取网卡信息并且用combbox选择并显示出来
发布网友
发布时间:2024-10-22 19:56
我来回答
共1个回答
热心网友
时间:2024-11-10 22:56
代码如下:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Management; //必须在项目中添加System.Management引用!
using System.Collections.Generic;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.Items.AddRange(GetNetcardName().ToArray());
}
// 获取计算机上安装的网卡名称
private List<string> GetNetcardName()
{
List<string> cardNames = new List<string>();
ManagementClass mc =
new ManagementClass("Win32_NetworkAdapter");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
cardNames.Add(mo["Description"].ToString());
}
return cardNames;
}
}
}