[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
按照上面思路可以这样:
  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
复制代码

TOP

本帖最后由 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

TOP

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
复制代码

TOP

本帖最后由 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
复制代码
1

评分人数

TOP

返回列表