Board logo

标题: [注册表类] [分享]批处理获取注册表指定网卡对应的MAC地址 [打印本页]

作者: Batcher    时间: 2024-5-28 17:47     标题: [分享]批处理获取注册表指定网卡对应的MAC地址

【问题描述】

求个检索HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}位置网卡关键字DriverDesc=VirtNet Network Adapter (NDIS 6.0)的子项,修改VirtNetMacAddress为指定值的bat



不一定是0019
"VirtNetMacAddress"=hex:01,02,03,04,05,06
作者: Batcher    时间: 2024-5-28 17:49

解决方案-1.bat
  1. @echo off
  2. set "FileTmp=%temp%\out.txt"
  3. reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}" /s > "%FileTmp%"
  4. for /f "delims=:" %%a in ('findstr /n /c:"DriverDesc    REG_SZ    VirtNet Network Adapter (NDIS 6.0)" "%FileTmp%"') do (
  5.     call :FindMac %%a
  6. )
  7. pause
  8. exit /b
  9. :FindMac
  10. for /f "skip=%1 tokens=1-3" %%a in ('type "%FileTmp%"') do (
  11.     if "%%a" == "VirtNetMacAddress" (
  12.         echo %%c
  13.         exit /b
  14.     )
  15. )
复制代码

作者: Batcher    时间: 2024-5-28 17:49

解决方案-2-不使用临时文件.bat
  1. @echo off
  2. for /f "delims=:" %%a in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}" /s ^| findstr /n /c:"DriverDesc    REG_SZ    VirtNet Network Adapter (NDIS 6.0)"') do (
  3.     call :FindMac %%a
  4. )
  5. pause
  6. exit /b
  7. :FindMac
  8. for /f "skip=%1 tokens=1-3" %%a in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}" /s') do (
  9.     if "%%a" == "VirtNetMacAddress" (
  10.         echo %%c
  11.         exit /b
  12.     )
  13. )
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2