Board logo

标题: [文本处理] [交流]批处理如何通过鲁大师日志提取硬件信息,重复数据太多 [打印本页]

作者: yakeyun    时间: 2022-7-24 18:02     标题: [交流]批处理如何通过鲁大师日志提取硬件信息,重复数据太多

本帖最后由 yakeyun 于 2022-7-26 00:07 编辑

鲁大师运行后会在程序安装路径下生成一个日志文件:C:\Program Files (x86)\LuDaShi\Log\ComputerZ_HardwareDll.log
这个里面包含了所有主机里面的硬件信息,但是自己通过下面代码提取后,出现许多重复项,也找不到规律来很好的提取信息。
  1. @echo off & setlocal enabledelayedexpansion
  2. pushd "C:\Program Files (x86)\LuDaShi\log"
  3. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[overviewinfowrapper] CPUName :"') do set CPUName=%%a
  4. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] Spd count:"') do set MemoryNumber=%%a
  5. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.0"') do set Memory0Name=%%a
  6. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.1"') do set Memory1Name=%%a
  7. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.2"') do set Memory2Name=%%a
  8. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.3"') do set Memory3Name=%%a
  9. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[gpuprocesser] VideoAdapter"') do set VideoAdapter=%%a
  10. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[motherboardinfowrapper] GetMotherboardInfo:"') do set MotherboardInfo=%%a
  11. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[monitorinfowrapper] find primary monitor"') do set monitor=%%a
  12. for /f "tokens=3* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[disk_client] ModelNumber"') do set Diskinfo=%%a
  13. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[0] ="') do set Network0=%%a
  14. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[1] ="') do set Network1=%%a
  15. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[2] ="') do set Network2=%%a
  16. for /f "tokens=2* delims=@" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[audioinfo] Multimedia(Hi-definition Audio):"') do set audioinfo=%%a
  17. set CPUName
  18. set MemoryNumber
  19. if !MemoryNumber! EQU 1 set Memory0Name
  20. if !MemoryNumber! EQU 2 set Memory0Name & set Memory1Name
  21. if !MemoryNumber! EQU 3 set Memory0Name & set Memory1Name & set Memory2Name
  22. if !MemoryNumber! EQU 4 set Memory0Name & set Memory1Name & set Memory2Name & set Memory3Name
  23. set VideoAdapter
  24. set MotherboardInfo
  25. set monitor
  26. set Diskinfo
  27. set Network0
  28. set Network1
  29. set Network2
  30. set audioinfo
  31. pause
复制代码
日志文件下载地址,数据重新打包了:
https://sanli.lanzoub.com/iLWkp08elamb




--------[ 鲁大师 ]----------------------------------------------------------------------------------

  软件:                 鲁大师 6.1022.3375.630
  时间:                 2022-07-25 20:41:10
  软件:                 http://www.ludashi.com

--------[ 概览 ]----------------------------------------------------------------------------------

  电脑型号               铭瑄 MS-TZZ H610M 台式电脑
  操作系统               Windows 11 专业版 64位(Version 21H2 / DirectX 12)

  处理器                 12th Gen Intel Core i5-12400F 六核
  主板                   铭瑄 MS-TZZ H610M(英特尔 PCH)
  显卡                   NVIDIA GeForce RTX 3050 ( 8 GB / 华硕 )
  内存                   16 GB ( 英睿达 DDR4 3200MHz 8GB / 镁光 DDR4 3200MHz 8GB )
  主硬盘                 技嘉 GP-GSM2NE3256GNTD (256 GB / 固态硬盘)
  显示器                 惠科 HKC2413 GF40 ( 23.6 英寸  )
  声卡                   英特尔 High Definition Audio 控制器
  网卡                   瑞昱 RTL8168/8111/8112 Gigabit Ethernet Controller

--------[ 主板 ]----------------------------------------------------------------------------------

  主板型号               铭瑄 MS-TZZ H610M
  芯片组                 英特尔 PCH
  序列号                 Default string
  BIOS                   安迈  International, LLC. 5.24  /  BIOS程序发布日期: 02/24/2022
  BIOS的大小             16384 KB

  板载设备               Device 1 / 未知 (启用)

--------[ 处理器 ]----------------------------------------------------------------------------------

  处理器                 12th Gen Intel Core i5-12400F 六核
  速度                   4.00 GHz
  处理器数量             核心数:6 / 线程数:12
  核心代号               Alder Lake
  生产工艺               10 nm
  插槽/插座              FCLGA1700
  一级数据缓存           6 x 48 KB, 12-Way, 64 byte lines
  一级代码缓存           6 x 32 KB, 8-Way, 64 byte lines
  二级缓存               6 x 1.25 MB, 10-Way, 64 byte lines
  三级缓存               18 MB, 12-Way, 64 byte lines
  特征                   MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, HTT, EM64T, EIST, Turbo Boost

--------[ 硬盘 ]----------------------------------------------------------------------------------

  产品                   技嘉  GP-GSM2NE3256GNTD (固态硬盘)
  大小                   256 GB
  固件                   EDFM90.0
  接口                   PCI-E 3x4
  数据传输率             4000.00 MB/秒
  特性                   S.M.A.R.T
  硬盘已使用             共 223 次,累计 968 小时

  产品                   酷兽  C5S-EVO 60G (固态硬盘)
  大小                   60 GB
  固件                   C1EC53
  接口                   SATA III
  数据传输率             600 MB/秒
  特性                   S.M.A.R.T,  APM,  48-bit LBA,  NCQ
  硬盘已使用             共 842 次,累计 4273 小时

  产品                   西数  WD5003ABYZ-011FA0
  大小                   500 GB
  固件                   19.01H19
  缓存                   64 MB
  接口                   SATA III
  数据传输率             600.00 MB/秒
  特性                   S.M.A.R.T,  48-bit LBA,  NCQ
  硬盘已使用             共 96 次,累计 409 小时
  转速                   7200 转/分

--------[ 内存 ]----------------------------------------------------------------------------------

  Controller0-ChannelA-DIMM0       英睿达 DDR4 3200MHz 8GB
  制造日期               2021 年 40 周
  型号                   CT8G4DFS632A.C4FE
  序列号                 E62849FB
  厂商                   Crucial
  模块位宽               64 Bits
  模块电压               SSTL 1.2V

  Controller1-ChannelA-DIMM0       镁光 DDR4 3200MHz 8GB
  制造日期               2020 年 27 周
  型号                   4ATF1G64AZ-3G2E1
  序列号                 28F80D36
  厂商                   Micron
  模块位宽               64 Bits
  模块电压               SSTL 1.2V

--------[ 显卡 ]----------------------------------------------------------------------------------

  主显卡                 NVIDIA GeForce RTX 3050
  显存                   8 GB
  频率                   核心: 1552MHz / 显存: 1750MHz
  显卡制造商             华硕
  芯片制造商             Nvidia
  BIOS版本               94.06.37.00.71
  驱动版本               30.0.15.1295
  驱动日期               20220519

--------[ 显示器 ]----------------------------------------------------------------------------------

  产品                   惠科 HKC2413 GF40
  厂商                   惠科
  固件程序日期           2019 年 11 周
  屏幕尺寸               23.6 英寸 (521 毫米 x 297 毫米)
  分辨率                 1920 x 1080 32 位真彩色
  Gamma                  2.20
  电源管理               Active-Off

--------[ 其他设备 ]----------------------------------------------------------------------------------

  网卡                   Realtek PCIe GbE Family Controller #2

  声卡                   英特尔 High Definition Audio 控制器

  声卡                   NVIDIA 标准 VGA 图形适配器 @ NVIDIA High Definition Audio 控制器
作者: hfxiang    时间: 2022-7-24 19:34

@echo off & setlocal enabledelayedexpansion
for /f "delims==" %%a in ('set GetPCVendor_ID[ 2^>nul') do set "%%a="
cd /d "%~dp0"
for /f "tokens=* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "GetPCVendor"') do (
        set "tmp_str=%%a"
        set "tmp_str=!tmp_str:*GetPCVendor=GetPCVendor!
        if not defined GetPCVendor_ID[!tmp_str!] (
                echo %%a
                set "GetPCVendor_ID[!tmp_str!]=True"
        )
)
作者: yakeyun    时间: 2022-7-25 13:19

本帖最后由 yakeyun 于 2022-7-25 13:25 编辑

回复 2# hfxiang


可以过滤,不过后面自己修改了下,获取后依然存在重复项。修改后的代码如下:
  1. @echo off & setlocal enabledelayedexpansion
  2. cd /d "%~dp0"
  3. echo.
  4. echo.
  5. for /f  "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[overviewinfowrapper] CPUName :"') do if not defined %%a set "%%a=%%a" & echo CPUName=%%a
  6. echo.
  7. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] Spd count:"') do echo MemoryNumber=%%a
  8. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.0"') do echo Memory0Name=%%a
  9. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.1"') do echo Memory1Name=%%a
  10. echo.
  11. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[gpuprocesser] VideoAdapter"') do if not defined %%a set "%%a=%%a" & echo VideoAdapter=%%a
  12. echo.
  13. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[motherboardinfowrapper] GetMotherboardInfo:"') do if not defined %%a set "%%a=%%a" & echo MotherboardInfo=%%a
  14. echo.
  15. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[monitorinfowrapper] find primary monitor"') do if not defined %%a set "%%a=%%a" & echo monitor=%%a
  16. echo.
  17. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[disk_client] PrimarayDiskModel:"') do if not defined %%a set "%%a=%%a" & echo Diskinfo=%%a
  18. echo.
  19. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[0] ="') do if not defined %%a set "%%a=%%a" & echo Network0=%%a
  20. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[1] ="') do if not defined %%a set "%%a=%%a" & echo Network1=%%a
  21. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[2] ="') do if not defined %%a set "%%a=%%a" & echo Network2=%%a
  22. echo.
  23. for /f "tokens=2* delims=@" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[audioinfo] Multimedia(Hi-definition Audio):"') do if not defined %%a set "%%a=%%a" & echo audioinfo=%%a
  24. pause
复制代码

作者: qixiaobin0715    时间: 2022-7-25 13:53

1.把代码中的所有echo修改为set;
2.在pause上面加上下面几行代码:
  1. set CPUName
  2. set Memory
  3. set VideoAdapter
  4. set MotherboardInfo
  5. set monitor
  6. set Diskinfo
  7. set audioinfo
复制代码

作者: yakeyun    时间: 2022-7-25 14:08

本帖最后由 yakeyun 于 2022-7-25 14:34 编辑

回复 4# qixiaobin0715

内存数量和每条内存信息会对不上
  1. @echo off & setlocal enabledelayedexpansion
  2. cd /d "%~dp0"
  3. for /f  "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[overviewinfowrapper] CPUName :"') do if not defined %%a set "%%a=%%a" & set CPUName=%%a
  4. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] Spd count:"') do set MemoryNumber=%%a
  5. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.0"') do set Memory0Name=%%a
  6. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.1"') do set Memory1Name=%%a
  7. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.1"') do set Memory2Name=%%a
  8. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.1"') do set Memory3Name=%%a
  9. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[gpuprocesser] VideoAdapter"') do if not defined %%a set "%%a=%%a" & set VideoAdapter=%%a
  10. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[motherboardinfowrapper] GetMotherboardInfo:"') do if not defined %%a set "%%a=%%a" & set MotherboardInfo=%%a
  11. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[monitorinfowrapper] find primary monitor"') do if not defined %%a set "%%a=%%a" & set monitor=%%a
  12. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[disk_client] PrimarayDiskModel:"') do if not defined %%a set "%%a=%%a" & set Diskinfo=%%a
  13. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[0] ="') do  if not defined %%a set "%%a=%%a" & set Network0=%%a
  14. for /f "tokens=2* delims==" %%b in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[1] ="') do if not defined %%b set "%%b=%%b" & set Network1=%%b
  15. for /f "tokens=2* delims==" %%c in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[2] ="') do if not defined %%c set "%%c=%%c" & set Network2=%%c
  16. for /f "tokens=2* delims=@" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[audioinfo] Multimedia(Hi-definition Audio):"') do if not defined %%a set "%%a=%%a" & set audioinfo=%%a
  17. set CPUName
  18. set MemoryNumber
  19. set Memory0Name
  20. set Memory1Name
  21. set Memory2Name
  22. set Memory3Name
  23. set VideoAdapter
  24. set MotherboardInfo
  25. set monitor
  26. set Diskinfo
  27. set Network0
  28. set Network1
  29. set Network2
  30. set audioinfo
  31. pause
复制代码

作者: qixiaobin0715    时间: 2022-7-25 14:32

不需要0123:
  1. set CPUName
  2. set Memory
  3. set VideoAdapter
  4. set MotherboardInfo
  5. set monitor
  6. set Diskinfo
  7. set Network
  8. set audioinfo
复制代码

作者: yakeyun    时间: 2022-7-25 15:14

本帖最后由 yakeyun 于 2022-7-25 15:23 编辑

回复 6# qixiaobin0715

如果存在多个硬盘的情况下,就无法正常输出硬盘,只会显示最后一个。
  1. @echo off & setlocal enabledelayedexpansion
  2. pushd "C:\Program Files (x86)\LuDaShi\log"
  3. for /f  "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[overviewinfowrapper] CPUName :"') do if not defined %%a set "%%a=%%a" & set CPUName=%%a
  4. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] Spd count:"') do set MemoryNumber=%%a
  5. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview."') do set MemoryName=%%a
  6. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[gpuprocesser] VideoAdapter"') do if not defined %%a set "%%a=%%a" & set VideoAdapter=%%a
  7. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[motherboardinfowrapper] GetMotherboardInfo:"') do if not defined %%a set "%%a=%%a" & set MotherboardInfo=%%a
  8. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[monitorinfowrapper] find primary monitor"') do if not defined %%a set "%%a=%%a" & set monitor=%%a
  9. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[disk_client] PrimarayDiskModel:"') do if not defined %%a set "%%a=%%a" & set Diskinfo=%%a
  10. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription"') do  if not defined %%a set "%%a=%%a" & set Network=%%a
  11. for /f "tokens=2* delims=@" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[audioinfo] Multimedia(Hi-definition Audio):"') do if not defined %%a set "%%a=%%a" & set audioinfo=%%a
  12. set CPUName
  13. set MemoryNumber
  14. set MemoryName
  15. set VideoAdapter
  16. set MotherboardInfo
  17. set monitor
  18. set Diskinfo
  19. set Network
  20. set audioinfo
  21. pause
复制代码

作者: qixiaobin0715    时间: 2022-7-25 15:53

本帖最后由 qixiaobin0715 于 2022-7-25 16:08 编辑

我是说按照顶楼的代码进行修改.
作者: yakeyun    时间: 2022-7-25 16:05

回复 8# qixiaobin0715

修改了下,加入判断内存条数条件后可以正常输出:
  1. @echo off & setlocal enabledelayedexpansion
  2. cd /d "%~dp0"
  3. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[overviewinfowrapper] CPUName :"') do set CPUName=%%a
  4. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] Spd count:"') do set MemoryNumber=%%a
  5. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.0"') do set Memory0Name=%%a
  6. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.1"') do set Memory1Name=%%a
  7. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.2"') do set Memory2Name=%%a
  8. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[processmemory] SpdOverview.3"') do set Memory3Name=%%a
  9. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[gpuprocesser] VideoAdapter"') do set VideoAdapter=%%a
  10. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[motherboardinfowrapper] GetMotherboardInfo:"') do set MotherboardInfo=%%a
  11. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[monitorinfowrapper] find primary monitor"') do set monitor=%%a
  12. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[disk_client] PrimarayDiskModel:"') do set Diskinfo=%%a
  13. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[0] ="') do set Diskinfo0=%%a
  14. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[1] ="') do set Diskinfo1=%%a
  15. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[2] ="') do set Diskinfo2=%%a
  16. for /f "tokens=2* delims=@" %%a in ('type "ComputerZ_HardwareDll.log" ^|find/i "[audioinfo] Multimedia(Hi-definition Audio):"') do set audioinfo=%%a
  17. set CPUName
  18. set MemoryNumber
  19. if !MemoryNumber! EQU 1 set Memory0Name
  20. if !MemoryNumber! EQU 2 set Memory0Name & set Memory1Name
  21. if !MemoryNumber! EQU 3 set Memory0Name & set Memory1Name & set Memory2Name
  22. if !MemoryNumber! EQU 4 set Memory0Name & set Memory1Name & set Memory2Name & set Memory3Name
  23. set VideoAdapter
  24. set MotherboardInfo
  25. set monitor
  26. set Diskinfo
  27. set audioinfo
  28. pause
复制代码

作者: qixiaobin0715    时间: 2022-7-25 16:28

为什么非要用type...^|find...形式呢?直接用findstr不行吗?比如顶楼第三行,你使用了:
  1. type "ComputerZ_HardwareDll.log" ^|find/i "[overviewinfowrapper] CPUName :"
复制代码
可改为:
  1. findstr /i /l /c:"[overviewinfowrapper] CPUName :" "ComputerZ_HardwareDll.log"
复制代码
这样不知是否可行?效率是否要高一些?
作者: yakeyun    时间: 2022-7-25 18:40

回复 10# qixiaobin0715


用findstr 会显示没有定义:
  1. @echo off & setlocal enabledelayedexpansion
  2. pushd "C:\Program Files (x86)\LuDaShi\log"
  3. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[overviewinfowrapper] CPUName :" "ComputerZ_HardwareDll.log"') do set CPUName=%%a
  4. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[processmemory] Spd count:" "ComputerZ_HardwareDll.log"') do set MemoryNumber=%%a
  5. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[processmemory] SpdOverview.0" "ComputerZ_HardwareDll.log"') do set Memory0Name=%%a
  6. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[processmemory] SpdOverview.1" "ComputerZ_HardwareDll.log"') do set Memory1Name=%%a
  7. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[processmemory] SpdOverview.2" "ComputerZ_HardwareDll.log"') do set Memory2Name=%%a
  8. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[processmemory] SpdOverview.3" "ComputerZ_HardwareDll.log"') do set Memory3Name=%%a
  9. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[gpuprocesser] VideoAdapter" "ComputerZ_HardwareDll.log"') do set VideoAdapter=%%a
  10. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[motherboardinfowrapper] GetMotherboardInfo:" "ComputerZ_HardwareDll.log"') do set MotherboardInfo=%%a
  11. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[monitorinfowrapper] find primary monitor" "ComputerZ_HardwareDll.log"') do set monitor=%%a
  12. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[disk_client] PrimarayDiskModel:" "ComputerZ_HardwareDll.log"') do set Diskinfo=%%a
  13. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[networkinfo] GetNetworkInfo: NetworkParams.strDescription[0] =" "ComputerZ_HardwareDll.log"') do set Network0=%%a
  14. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[networkinfo] GetNetworkInfo: NetworkParams.strDescription[1] =" "ComputerZ_HardwareDll.log"') do set Network1=%%a
  15. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[networkinfo] GetNetworkInfo: NetworkParams.strDescription[2] =" "ComputerZ_HardwareDll.log"') do set Network2=%%a
  16. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[audioinfo] Multimedia(Hi-definition Audio):" "ComputerZ_HardwareDll.log"') do set audioinfo=%%a
  17. set CPUName
  18. set MemoryNumber
  19. if !MemoryNumber! EQU 1 set Memory0Name
  20. if !MemoryNumber! EQU 2 set Memory0Name & set Memory1Name
  21. if !MemoryNumber! EQU 3 set Memory0Name & set Memory1Name & set Memory2Name
  22. if !MemoryNumber! EQU 4 set Memory0Name & set Memory1Name & set Memory2Name & set Memory3Name
  23. set VideoAdapter
  24. set MotherboardInfo
  25. set monitor
  26. set Diskinfo
  27. set Network0
  28. set Network1
  29. set Network2
  30. set audioinfo
  31. pause
复制代码

作者: yakeyun    时间: 2022-7-25 23:45

本帖最后由 yakeyun 于 2022-7-26 00:40 编辑

回复 11# yakeyun

自己慢慢摸索,差不多已经找到最完美的方案了。加入if defined命令,避免出现获取不到信息,显示异常情况。
  1. @echo off & setlocal enabledelayedexpansion
  2. pushd "C:\Program Files (x86)\LuDaShi\log"
  3. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[overviewinfowrapper] CPUName :"') do set CPUName=%%a
  4. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[processmemory] Spd count:"') do set MemoryNumber=%%a
  5. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[processmemory] SpdOverview.0"') do set Memory0Name=%%a
  6. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[processmemory] SpdOverview.1"') do set Memory1Name=%%a
  7. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[processmemory] SpdOverview.2"') do set Memory2Name=%%a
  8. for /f "tokens=4* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[processmemory] SpdOverview.3"') do set Memory3Name=%%a
  9. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[gpuprocesser] VideoAdapter"') do set VideoAdapter=%%a
  10. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[motherboardinfowrapper] GetMotherboardInfo:"') do set MotherboardInfo=%%a
  11. for /f "tokens=4* delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[monitorinfowrapper] find primary monitor"') do set monitor=%%a
  12. for /f "tokens=1 delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i /c "[disk_client] ModelNumber"') do set DiskNumber=%%a
  13. for /f "tokens=1 delims=:" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i /c "[disk_client] ModelNumber"') do set DiskNumber=%%a
  14. if !DiskNumber! EQU 1 (for /f "tokens=3* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[disk_client] ModelNumber"') do set Disk0Number=%%a)
  15. if !DiskNumber! EQU 2 (for /f "tokens=3* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[disk_client] ModelNumber"') do (
  16. set /a n+=1
  17. set /a num=n%%!DiskNumber!
  18. if !num! EQU 0 set Disk0Number=%%a
  19. if !num! EQU 1 set Disk1Number=%%a
  20. ))
  21. if !DiskNumber! EQU 3 (for /f "tokens=3* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[disk_client] ModelNumber"') do (
  22. set /a n+=1
  23. set /a num=n%%!DiskNumber!
  24. if !num! EQU 0 set Disk0Number=%%a
  25. if !num! EQU 1 set Disk1Number=%%a
  26. if !num! EQU 2 set Disk2Number=%%a
  27. ))
  28. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[0]"') do set Network0=%%a
  29. for /f "tokens=2* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "[networkinfo] GetNetworkInfo: NetworkParams.strDescription[1]"') do set Network1=%%a
  30. for /f "tokens=6* delims==" %%a in ('type "ComputerZ_HardwareDll.log" ^|find /i "Realtek High Definition Audio"') do set audio0=%%a
  31. if defined CPUName set CPUName
  32. if defined MemoryNumber set MemoryNumber
  33. if !MemoryNumber! EQU 1 set Memory0Name
  34. if !MemoryNumber! EQU 2 set Memory0Name & set Memory1Name
  35. if !MemoryNumber! EQU 3 set Memory0Name & set Memory1Name & set Memory2Name
  36. if !MemoryNumber! EQU 4 set Memory0Name & set Memory1Name & set Memory2Name & set Memory3Name
  37. if defined VideoAdapter set VideoAdapter
  38. if defined MotherboardInfo set MotherboardInfo
  39. if defined monitor set monitor
  40. if defined DiskNumber set DiskNumber
  41. if !DiskNumber! EQU 1 set Disk0Number
  42. if !DiskNumber! EQU 2 set Disk0Number & set Disk1Number
  43. if !DiskNumber! EQU 3 set Disk0Number & set Disk1Number & set Disk2Number
  44. if defined Network0 set Network0
  45. if defined Network1 set Network1
  46. if defined audio0 set audio0
  47. pause
复制代码

作者: hfxiang    时间: 2022-7-26 09:11

回复 3# yakeyun


请注意,2楼的绝大多数代码服务于关于键字“GetPCVendor”的“去重”,其实只要把“去重”代码服稍作修改从而务于其它各关键字就能出结果
作者: qixiaobin0715    时间: 2022-7-26 10:11

回复 11# yakeyun
1.你的要求没有说清楚;
2.代码没有写对。
按你的代码形式可以这样:
  1. @echo off&setlocal enabledelayedexpansion
  2. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[overviewinfowrapper] CPUName :" "ComputerZ_HardwareDll.log"') do set CPUName=%%a
  3. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[processmemory] Spd count:" "ComputerZ_HardwareDll.log"') do set Memory Number=%%a
  4. for /f "tokens=4* delims==" %%a in ('findstr /i /l /c:"[processmemory] SpdOverview.0" "ComputerZ_HardwareDll.log"') do set Memory0Name=%%a
  5. for /f "tokens=4* delims==" %%a in ('findstr /i /l /c:"[processmemory] SpdOverview.1" "ComputerZ_HardwareDll.log"') do set Memory1Name=%%a
  6. for /f "tokens=4* delims==" %%a in ('findstr /i /l /c:"[processmemory] SpdOverview.2" "ComputerZ_HardwareDll.log"') do set Memory2Name=%%a
  7. for /f "tokens=4* delims==" %%a in ('findstr /i /l /c:"[processmemory] SpdOverview.3" "ComputerZ_HardwareDll.log"') do set Memory3Name=%%a
  8. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[gpuprocesser] VideoAdapter" "ComputerZ_HardwareDll.log"') do set VideoAdapter=%%a
  9. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[motherboardinfowrapper] GetMotherboardInfo:" "ComputerZ_HardwareDll.log"') do set MotherboardInfo=%%a
  10. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[monitorinfowrapper] find primary monitor" "ComputerZ_HardwareDll.log"') do set monitor=%%a
  11. set DiskNumber=0
  12. for /f "tokens=3* delims==" %%a in ('findstr /i /l /c:"[disk_client] ModelNumber" "ComputerZ_HardwareDll.log"') do (
  13. set Disk!DiskNumber!Number=%%a
  14. set /a DiskNumber+=1
  15. )
  16. set Disk Number=!DiskNumber!
  17. set DiskNumber=
  18. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[networkinfo] GetNetworkInfo: NetworkParams.strDescription[0] =" "ComputerZ_HardwareDll.log"') do set Network0=%%a
  19. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[networkinfo] GetNetworkInfo: NetworkParams.strDescription[1] =" "ComputerZ_HardwareDll.log"') do set Network1=%%a
  20. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[networkinfo] GetNetworkInfo: NetworkParams.strDescription[2] =" "ComputerZ_HardwareDll.log"') do set Network2=%%a
  21. for /f "tokens=2* delims=@" %%a in ('findstr /i /l /c:"[audioinfo] Multimedia(Hi-definition Audio):" "ComputerZ_HardwareDll.log"') do set audioinfo=%%a
  22. set CPUName
  23. set Memory
  24. set VideoAdapter
  25. set MotherboardInfo
  26. set monitor
  27. set Disk
  28. set Network
  29. set audioinfo
  30. pause
复制代码

作者: qixiaobin0715    时间: 2022-7-26 10:46

可以一次读取所有符合条件的行,再分别处理。这样效率就会高很多。
作者: qixiaobin0715    时间: 2022-7-26 13:36

按照上面思路可以这样:
  1. @echo off & setlocal enabledelayedexpansion
  2. set m=0
  3. set n=0
  4. set x=0
  5. set Order=findstr /i /l /c:"[overviewinfowrapper] CPUName :" /c:"[processmemory] SpdOverview." /c:"[gpuprocesser] VideoAdapter" /c:"[motherboardinfowrapper] GetMotherboardInfo:" /c:"[monitorinfowrapper] find primary monitor" /c:"[disk_client] ModelNumber" /c:"[networkinfo] GetNetworkInfo: NetworkParams.strDescription" /c:"[audioinfo] Multimedia(Hi-definition Audio):" "ComputerZ_HardwareDll.log"
  6. for /f "tokens=9-12 delims=]:=" %%a in ('%Order%') do (
  7.     set str=%%a
  8.     set str=!str:~1,4!
  9.     if "!str!"=="CPUN" (
  10.         set CPUName=%%b
  11.     ) else if "!str!"=="GetM" (
  12.         set MotherboardInfo=%%b
  13.     ) else if "!str!"=="GetN" (
  14.         for /f "tokens=2 delims=[" %%i in ("%%b") do set Network%%i=%%d
  15.     ) else if "!str!"=="Mode" (
  16.         set Disk!m!Number=%%c
  17.         set /a m+=1
  18.     ) else if "!str!"=="Mult" (
  19.         for /f "tokens=2 delims=@" %%i in ("%%b") do set audio!n!=%%i
  20.         set /a n+=1
  21.     ) else if "!str!"=="SpdO" (
  22.         for /f "tokens=2 delims=. " %%i in ("%%a") do set Memory!x!Name=%%d
  23.         set /a x+=1
  24.     ) else if "!str!"=="Vide" (
  25.         set VideoAdapter=%%b
  26.     ) else if "!str!"=="find" (
  27.         set monitor=%%b
  28.     )
  29. )
  30. set CPUName
  31. set Memory
  32. set VideoAdapter
  33. set MotherboardInfo
  34. set monitor
  35. set Disk
  36. set Network
  37. set audio
  38. pause
复制代码

作者: yakeyun    时间: 2022-7-26 17:58

本帖最后由 yakeyun 于 2022-7-26 20:58 编辑

回复 14# qixiaobin0715

因为对findstr命令没有深入了解过,所以对用法不是很熟悉,感谢指导。
这个修改后的版本已经很完美了,不过对这种用法也是第一次了解到,在没有用echo命令,仅仅用set命令就可以将内容输出。
  1. @echo off&setlocal enabledelayedexpansion
  2. pushd "C:\Program Files (x86)\LuDaShi\log"
  3. if exist "C:\Program Files (x86)\LuDaShi\log\ComputerZ_HardwareDll.log" (set top=[硬件参数])
  4. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[overviewinfowrapper] CPUName :" "ComputerZ_HardwareDll.log"') do set CPUName=%%a
  5. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[processmemory] Spd count:" "ComputerZ_HardwareDll.log"') do set Memory Number=%%a
  6. for /f "tokens=4* delims==" %%a in ('findstr /i /l /c:"[processmemory] SpdOverview.0" "ComputerZ_HardwareDll.log"') do set Memory0Name=%%a
  7. for /f "tokens=4* delims==" %%a in ('findstr /i /l /c:"[processmemory] SpdOverview.1" "ComputerZ_HardwareDll.log"') do set Memory1Name=%%a
  8. for /f "tokens=4* delims==" %%a in ('findstr /i /l /c:"[processmemory] SpdOverview.2" "ComputerZ_HardwareDll.log"') do set Memory2Name=%%a
  9. for /f "tokens=4* delims==" %%a in ('findstr /i /l /c:"[processmemory] SpdOverview.3" "ComputerZ_HardwareDll.log"') do set Memory3Name=%%a
  10. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[gpuprocesser] VideoAdapter" "ComputerZ_HardwareDll.log"') do set VideoAdapter=%%a
  11. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[motherboardinfowrapper] GetMotherboardInfo:" "ComputerZ_HardwareDll.log"') do set MotherboardInfo=%%a
  12. for /f "tokens=4* delims=:" %%a in ('findstr /i /l /c:"[monitorinfowrapper] find primary monitor" "ComputerZ_HardwareDll.log"') do set monitor=%%a
  13. set DiskNumber=0
  14. for /f "tokens=3* delims==" %%a in ('findstr /i /l /c:"[disk_client] ModelNumber" "ComputerZ_HardwareDll.log"') do (
  15. set Disk!DiskNumber!Number=%%a
  16. set /a DiskNumber+=1
  17. )
  18. set Disk Number=!DiskNumber!
  19. set DiskNumber=
  20. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[networkinfo] GetNetworkInfo: NetworkParams.strDescription[0] =" "ComputerZ_HardwareDll.log"') do set Network0=%%a & set Network Number=1
  21. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[networkinfo] GetNetworkInfo: NetworkParams.strDescription[1] =" "ComputerZ_HardwareDll.log"') do set Network1=%%a & set Network Number=2
  22. for /f "tokens=2* delims==" %%a in ('findstr /i /l /c:"[networkinfo] GetNetworkInfo: NetworkParams.strDescription[2] =" "ComputerZ_HardwareDll.log"') do set Network2=%%a & set Network Number=3
  23. set AudioNumber=0
  24. for /f "tokens=2* delims=@" %%a in ('findstr /i /l /c:"[audioinfo] Multimedia(Hi-definition Audio):" "ComputerZ_HardwareDll.log"') do (
  25. set Audio!AudioNumber!Number=%%a
  26. set /a AudioNumber+=1
  27. )
  28. set Audio Number=!AudioNumber!
  29. set AudioNumber=
  30. cd /d "%~dp0"
  31. (
  32. echo %top%
  33. set CPUName
  34. set Memory
  35. set VideoAdapter
  36. set MotherboardInfo
  37. set monitor
  38. set Disk
  39. set Network Number
  40. set Network
  41. set audio
  42. )>sysinfo.ini
复制代码




有一点不是很理解:
如果将Network Number 改成NetworkNumber
set NetworkNumber
set Network

最后显示结果会变成:
NetworkNumber=2
Network0= 英特尔 Wi-Fi 6 AX201 160MHz
Network1= 瑞昱 Realtek Gaming 2.5GbE Family Controller / 华硕
NetworkNumber=2
Audio Number=2

NetworkNumber=2会出现2次。


鲁大师日志下载地址:
https://sanli.lanzoub.com/izxDU08g4k7g
作者: qixiaobin0715    时间: 2022-7-27 09:11

set和findstr用法可看这里http://bbs.bathome.net/viewthrea ... &from=favorites
不设置变量的set(不带等号和变量值),比如:
set a         显示以a开头的变量(包括环境变量及自定义变量)
set aa       显示以aa开头的变量
set aaa     显示以aaa开头的变量
同理
set Network   会显示以Network开头的所有变量包括NetworkNumber:
  1. Network0= 英特尔 Wi-Fi 6 AX201 160MHz
  2. Network1= 瑞昱 Realtek Gaming 2.5GbE Family Controller / 华硕
  3. NetworkNumber=2
复制代码
变量会根据变量名的正序显示。NetworkNumber=2会最后一个显示。
而在前面你有一行
set NetworkNumber
也会显示变量NetworkNumber。就会产生重复的情况。
如果既不想重复显示,又要把变量NetworkNumber=2显示在Network0 Network1的前面。可以这样:
  1. set NetworkNumber
  2. set NetworkNumber=
  3. set Network
复制代码

作者: qixiaobin0715    时间: 2022-7-27 11:01

本帖最后由 qixiaobin0715 于 2022-7-29 09:32 编辑

如果非要按照17楼的格式显示的话,可将16楼代码进行修改,效率要高不少,代码另存为ANSI编码:
  1. @echo off & setlocal enabledelayedexpansion
  2. set DiskNumber=0
  3. set AudioNumber=0
  4. set MemoryNumber=0
  5. set Order=findstr /i /l /c:"[overviewinfowrapper] CPUName :" /c:"[processmemory] SpdOverview." /c:"[gpuprocesser] VideoAdapter" /c:"[motherboardinfowrapper] GetMotherboardInfo:" /c:"[monitorinfowrapper] find primary monitor" /c:"[disk_client] ModelNumber" /c:"[networkinfo] GetNetworkInfo: NetworkParams.strDescription" /c:"[audioinfo] Multimedia(Hi-definition Audio):" "ComputerZ_HardwareDll.log"
  6. for /f "tokens=9-12 delims=]:=" %%a in ('%Order%') do (
  7.     set str=%%a
  8.     set str=!str:~1,4!
  9.     if "!str!"=="CPUN" (
  10.         set CPUName=%%b
  11.     ) else if "!str!"=="GetM" (
  12.         set MotherboardInfo=%%b
  13.     ) else if "!str!"=="GetN" (
  14.         for /f "tokens=2 delims=[" %%i in ("%%b") do (
  15.             if not defined _%%i (
  16.                 set /a NetworkNumber+=1
  17.                 set Network%%i=%%d
  18.                 set _%%i=true
  19.             )
  20.         )
  21.     ) else if "!str!"=="Mode" (
  22.         set Disk!DiskNumber!Number=%%c
  23.         set /a DiskNumber+=1
  24.     ) else if "!str!"=="Mult" (
  25.         for /f "tokens=2 delims=@" %%i in ("%%b") do set Audio!AudioNumber!Number=%%i
  26.         set /a AudioNumber+=1
  27.     ) else if "!str!"=="SpdO" (
  28.         for /f "tokens=2 delims=. " %%i in ("%%a") do set Memory!MemoryNumber!Name=%%d
  29.         set /a MemoryNumber+=1
  30.     ) else if "!str!"=="Vide" (
  31.         set VideoAdapter=%%b
  32.     ) else if "!str!"=="find" (
  33.         set monitor=%%b
  34.     )
  35. )
  36. echo [硬件参数]
  37. set CPUName
  38. set MemoryNumber
  39. set MemoryNumber=
  40. set Memory
  41. set VideoAdapter
  42. set MotherboardInfo
  43. set monitor
  44. set DiskNumber
  45. set DiskNumber=
  46. set Disk
  47. set NetworkNumber
  48. set NetworkNumber=
  49. set Network
  50. set AudioNumber
  51. set AudioNumber=
  52. set Audio
  53. pause
复制代码





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