Option Explicit
Private Sub Form_Load() Dim oWMI As Object, oLocal As Object, oHARDWARE As Object, object1 As Object Dim lcCPUID, LcMAC, LcIP, lcHDID, lcSerial '以上定义对象和变量,有的没有用的 Set oWMI = CreateObject("WbemScripting.SWbemLocator") Set oLocal = oWMI.ConnectServer(".", "root\cimv2")
Set oHARDWARE = oLocal.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled=1") For Each object1 In oHARDWARE LcMAC = object1.Properties_("MACAddress").Value LcIP = object1.Properties_("IPAddress").Value Debug.Print "网卡MAC地址:", LcMAC List1.AddItem "MAC:" & LcMAC & " IP:" & LcIP(0) 'lcmac其实是一个数组,所以要用数组的方法读出来,如果只要一个,也可直接用lcmac(0) ' For I = LBound(LcIP) To UBound(LcIP) ' Debug.Print LcIP(I); ' Next ' Print Next End Sub
|
在窗体上添加一个LIST。
代码来源:http://hi.baidu.com/era_xu/blog/item/2869f6339e1215f11a4cff0e.html
阅读(2889) | 评论(0) | 转发(0) |