回 帖 发 新 帖 刷新版面

主题:[讨论]vb取mac地址的ocx不正常工作

本人用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个回复)

沙发

支持楼主!虽然我不懂啊· --------------------------------------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]

板凳

其实,使用icePubDll.dll这个就可以了,网上有很多资料。

3 楼

这个有待研究。
用第三方的dll是简洁的好方法

4 楼

提供一个函数,可以获取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 楼

这个有待研究

6 楼

[quote]这个有待研究[/quote]
哥哥,发有意义的内容吧

我来回复

您尚未登录,请登录后再回复。点此登录或注册