用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 展开
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 展开
1个回答
展开全部
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
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 广告
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询