我在网上找到以下代码获取本机MAC地址:
Public Function NetworkAdapterConfig() As StringDim wmiObjSet As SWbemObjectSet
Dim obj As SWbemObjectSet wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_NetworkAdapterConfiguration")
On Local Error Resume NextFor Each obj In wmiObjSet
NetworkAdapterConfig = obj.MACAddress
NextEnd Function在我笔记本上运行时读取MAC地址正确,但在台式机上运行时读取的MAC地址是不正确的,而且重启电脑后读取的和之前的又不一样。请高手指点!!!!

解决方案 »

  1.   

        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
                For i = LBound(IP.ipaddress) To UBound(IP.ipaddress)
                    Mac = IP.macaddress(i)
                    descrip = IP.Description(i)
                    MsgBox "IP 地址:" & IP.ipaddress(I) & Chr(10) & _
                    "网卡类型:" & IP.Description(I) & Chr(10) & _
                    "网卡地址:" & IP.macaddress(I)
                Next
            End If
        Next
      

  2.   

    cmd 中使用   ipconfig /all