取本机Mac相关信息

0 Reply , Posted in 程序代码 on 2018 27, 2018

'代码出处:http://zhidao.baidu.com/question/155475470.html
Private Sub Form_Load()
Dim Mac
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

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)
Text1.Text = Ip.ipaddress(I)   '取内网IP地址
Text2.Text = Ip.Description(I) '取网卡类型
Text3.Text = Ip.macaddress(I)  '取MAC地址
Next

End If

Next
End Sub

发表评论:



◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

                       

  鄂公网安备 42112502000156号     鄂ICP备16019550号