我想从 Windows 系统检索 MAC 地址,仅适用于 LAN 适配器。你能告诉我如何在 VBScript 中处理这个问题吗?
我目前正在使用此 VBScript 来获取 MAC 地址,但这为我提供了所有适配器的结果,而我只需要连接 LAN 适配器时的 MAC 地址。
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
If objItem.ServiceName <> "VMnetAdapter" AND isNull(objItem.MACAddress)=0 Then
Wscript.Echo objItem.MACAddress
Wscript.Echo objItem.ServiceName
End if
Next
最佳答案
使用Win32_NetworkAdapter
类而不是 Win32_NetworkAdapterConfiguration
类。后者没有提供适配器名称的属性。
adaptername = "LAN Adapter"
Set wmi = GetObject("winmgmts://./root/cimv2")
qry = "SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID = '" & adaptername & "'"
For Each adapter In wmi.ExecQuery(qry)
If Not IsNull(adapter.MACAddress) Then Wscript.Echo adapter.MACAddress
Next
关于windows - 如何检索 LAN 适配器 MAC 地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30778071/