主题:[讨论]vb取mac地址的ocx不正常工作
gslzzhg
[专家分:0] 发布于 2012-12-27 20:22:00
本人用VB写了一个取硬件信息的OCX,但不能正常使用,请高手指点一下为何
谢谢
Public Sub UserControl_Initialize()
strComputer = "."
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
Text1.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
Text2.Text = Trim(Text2.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
Public Property Get PosX() As String '取得MAC的值显示给用户
PosX = Text1.Text
End Property
Public Property Get PosY() As String '取得ip的值显示给用户
PosY = Text2.Text
End Property
回复列表 (共6个回复)
沙发
biansky [专家分:10] 发布于 2013-01-31 17:49:00
支持楼主!虽然我不懂啊· --------------------------------------Jordan putfew people know that is the [url=http://www.retrojordansnew.com/air-jordan-5-retro-c-24.html]jordan retro 5[/url] ,[url=http://www.retrojordansnew.com/air-jordan-4-retro-c-23.html]jordan retro 4[/url] , [url=http://www.retrojordansnew.com/air-jordan-6-retro-c-1.html]jordan retro 6[/url] , [url=http://www.retrojordansnew.com/air-jordan-7-retro-c-2.html]jordan retro 7[/url] , [url=http://www.retrojordansnew.com/air-jordan-8-retro-c-35.html]jordan retro 8[/url] , [url=http://www.retrojordansnew.com/air-jordan-9-retro-c-25.html]jordan retro 9[/url] , [url=http://www.retrojordansnew.com/air-jordan-11-retro-c-16.html]jordan retro 11[/url] , [url=http://www.retrojordansnew.com/air-jordan-13-retro-c-17.html]jordan retro 13[/url]
板凳
孙瑞 [专家分:590] 发布于 2013-02-05 23:44:00
其实,使用icePubDll.dll这个就可以了,网上有很多资料。
3 楼
孙瑞 [专家分:590] 发布于 2014-04-24 14:25:00
这个有待研究。
用第三方的dll是简洁的好方法
4 楼
孙瑞 [专家分:590] 发布于 2014-04-24 22:10:00
提供一个函数,可以获取mac地址
Function GetMyMac()
Dim strComputer As String
Dim objWMI As Object
Dim colIP As Object
Dim IP As Object
Dim i As Integer
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
GetMyMac = LCase(IP.macAddress(i))
Exit Function
End If
Next
End Function
5 楼
网络雄风 [专家分:90] 发布于 2014-04-26 16:22:00
这个有待研究
6 楼
孙瑞 [专家分:590] 发布于 2014-05-12 13:23:00
[quote]这个有待研究[/quote]
哥哥,发有意义的内容吧
我来回复