VBA讀網卡MAC
Dim Str$, Arr, N&, i&, FN$Dim k
FN = ThisWorkbook.Path & "\IpInfo.txt"
With CreateObject("wscript.shell")
.Run Environ("comspec") & " /c ipconfig /all>""" & FN & """", 0, 1
End With
With CreateObject("scripting.filesystemobject").opentextfile(FN)
Str = .readall
.Close
End With
Kill FN
Arr = Split(Str, vbNewLine)
For i = LBound(Arr) To UBound(Arr)
If LCase(Arr(i)) Like "*physical address*:*" Then
k = Trim(Split(Arr(i), ":")(1))
k = Mid(k, 1, 2) & Mid(k, 4, 2) & Mid(k, 7, 2) & Mid(k, 10, 2) & Mid(k, 13, 2) & Mid(k, 16, 2)
End If
Next i
這段代碼在XP下是沒有問題的,能讀到外接的網卡,但在WIN7下就不行了,求指正