用VB获取MAC地址

哪位大虾看看我这程序,是用来获取MAC地址的,问什么总是不能运行啊!PrivateSubForm_Load()DimMacstrComputer="."Mac=""'获得... 哪位大虾看看我这程序,是用来获取MAC地址的,问什么总是不能运行啊!
Private Sub Form_Load()
Dim Mac
strComputer = "."
Mac = ""

'获得MAC信息
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each objItem In colItems
Mac = Mac + " " + objItem.macaddress
Next
TeMac.Text = Replace(Trim(Mac), ":", "-")

strComputer = "."
Set objWMI = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set colIP = objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each Ip In colIP
If Not IsNull(Ip.ipaddress) Then
For I = LBound(Ip.ipaddress) To UBound(Ip.ipaddress)
'Mac = Ip.macaddress(I)objObject.DNSHostName
If Ip.ipaddress(I) = "0.0.0.0" Then
Else

TeIp.Text = Trim(TeIp.Text + " " + Ip.ipaddress(I))
End If
'MsgBox "IP 地址:" & IP.ipaddress(I) & Chr(10) & _
"网卡类型:" & IP.Description(I) & Chr(10) & _
"网卡地址:" & IP.macaddress(I)
Next
End If
Next
展开
 我来答
远风的梦想家
2010-05-26 · TA获得超过2550个赞
知道大有可为答主
回答量:1389
采纳率:0%
帮助的人:0
展开全部
Private Sub Form_Load()
Dim Mac
strComputer = "."
Mac = ""

'获得MAC信息

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2")'''加上这个
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each objItem In colItems
Mac = Mac + " " + objItem.macaddress
Next
TeMac.Text = Replace(Trim(Mac), ":", "-")

strComputer = "."
Set objWMI = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set colIP = objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each Ip In colIP
If Not IsNull(Ip.ipaddress) Then
For i = LBound(Ip.ipaddress) To UBound(Ip.ipaddress)
'Mac = Ip.macaddress(I)objObject.DNSHostName
If Ip.ipaddress(i) = "0.0.0.0" Then
Else

TeIp.Text = Trim(TeIp.Text + " " + Ip.ipaddress(i))
End If
'MsgBox "IP 地址:" & IP.ipaddress(I) & Chr(10) & _
"网卡类型:" & IP.Description(I) & Chr(10) & _
"网卡地址:" & IP.macaddress(I)
Next
End If
Next
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
Storm代理
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企... 点击进入详情页
本回答由Storm代理提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式