用vb.net如何取得mac地址?

用vb.net如何取得mac地址?
我用的是VB 2008。
我这样写
Dim Wmi As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration")

可总提示我System.Management.ManagementObjectSearcher没有定义。请问是什么原因呢?谢谢!
最新回答
鲜血染红嫁衣

2024-10-02 00:04:56

这是C#的,你可以转换一下

using System.Management;

//获取网卡的系列号
private static string GetMacAddress()
{
string ret = "";
try
{
ManagementClass cimobject = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = cimobject.GetInstances();
if (moc.Count == 0)
return "";
else
{
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
ret = (string)mo.Properties["MacAddress"].Value;
break;
}
}
}
}
catch
{
ret = "";
}
return ret;
}
若樱落如烟

2024-10-02 00:05:21

要先添加引用
山城夏秋

2024-10-02 00:04:22

是不是忘了using System.Management?