windows - 如何检索 LAN 适配器 MAC 地址?

标签 windows vbscript

我想从 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/

相关文章:

vbscript - 如何从字符串中删除前导零

.net - MySQL Workbench 5.2.42 在 Win7 x64 上启动时崩溃

windows - 如何从任何进程关闭 Windows 上的套接字(ipv4 和 ipv6)连接?

python - Windows 上的 multiprocessing.Pool.apply_async

c++ - 检查 Windows 版本

vbscript - VBS : For-each loop (sometimes) iterates through file collection indefinitely

Windows 更新破坏了多部分/表单数据(更新 : KB3104002 )

if-statement - VBScript - 如何生成随机数,然后使用 If 语句使用该数字来选择选项

vbscript - 防止 VBscript 应用程序显示控制台窗口

c++ - WM_PAINT 与 PROGRESS_CLASS