向各位高手求C#获得MAC号的代码
来源:百度知道 编辑:UC知道 时间:2024/06/26 00:24:01
代码如下:记得在 引用 里面添加对C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727目录下System.Management.dll的引用
在Form1上拖放一个Lable即可
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Management;
using System.Windows.Forms;
namespace MACGETTER
{
public partial class Form1 : Form
{
public string MacAddress;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.label1.Text = GetMacAddress();
}
string GetMacAddress()
{
try
{
//获取网卡硬件地址
string mac = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in