本帖最后由 a7701 于 2012-6-24 17:59 编辑
个人整理的硬件信息收集批处理,请教各位前辈还能不能再优化代码。- @echo off
- color 0a
- title 硬件检测
- mode con cols=40 lines=10
- sc config winmgmt start= auto >nul 2<&1
- net start winmgmt 2>nul
- setlocal ENABLEDELAYEDEXPANSION
- set file=!computername!.txt
- set txt=info.tmp
- if exist !file! del !file!
-
- cls
- echo.
- echo 正在收集硬件信息中,请稍候......
- echo --------------------------------
- echo ┏━━━━━━━━━━━━━━━┓
- echo ┃ !!!请勿关闭本程序!!! ┃
- echo ┃ 如果程序打扰了您的工作 ┃
- echo ┃ 请把程序最小化 ┃
- echo ┗━━━━━━━━━━━━━━━┛
- echo --------------------------------
- ::从DXDIAG里获取主机型号、CPU、内存信息
- dxdiag /t !txt!
- for /f "tokens=2 delims=:" %%i in ('type !txt! ^| findstr /i /c:"System Model"') do set XH=%%i
- for /f "tokens=2 delims=:" %%i in ('type !txt! ^| findstr /i /c:" Processor:"') do set CPU=%%i
- for /f "tokens=2 delims=:" %%i in ('type !txt! ^| findstr /c:" Memory:"') do set NC=%%i
-
- ::内存容量取整
- set /a mmem=!NC:~0,-6!
- if !mmem! LEQ 800 set mem=!mmem!MB
- if !mmem! LEQ 1250 (
- if !mmem! GEQ 850 (
- set mem=1G
- )
- )
- if !mmem! LEQ 1750 (
- if !mmem! GEQ 1250 (
- set mem=1.5G
- )
- )
- if !mmem! LEQ 2250 (
- if !mmem! GEQ 1750 (
- set mem=2G
- )
- )
- if !mmem! GEQ 3250 set mem=4G
-
- ::用WMIC命令获取硬盘型号与硬盘容量
- for /f "skip=1 tokens=*" %%i in ('wmic DISKDRIVE get caption') do (
- if not "%%i"=="" (set/a n+=1&set HDD!n!=%%i)
- )
- for /f "skip=1 delims=" %%i in ('wmic DISKDRIVE get size') do call set 硬盘大小=!!硬盘大小!! %%i
- for /f "tokens=1,2,3,4" %%i in ("!硬盘大小!") do call set Size1=%%i&set Size2=%%j&set Size3=%%k&set Size4=%%l
-
- ::硬盘容量取整
- set /a Size1=!Size1:~0,-9!
- set /a Size2=!Size2:~0,-9!
- set /a Size3=!Size3:~0,-9!
- set /a Size4=!Size4:~0,-9!
- if !Size1:~-1! LEQ 9 (
- if !Size1:~-1! GEQ 1 (
- set /a size1=!size1!+1
- )
- )
- if !Size2:~-1! LEQ 9 (
- if !Size2:~-1! GEQ 1 (
- set /a size2=!size2!+1
- )
- )
- if !Size3:~-1! LEQ 9 (
- if !Size3:~-1! GEQ 1 (
- set /a size3=!size3!+1
- )
- )
- if !Size4:~-1! LEQ 9 (
- if !Size4:~-1! GEQ 1 (
- set /a size4=!size4!+1
- )
- )
- if !Size1! GEQ 40 set /a size1=!size1!-!Size1:~-1!
- if !Size2! GEQ 40 set /a size2=!size2!-!Size2:~-1!
- if !Size3! GEQ 40 set /a size3=!size3!-!Size3:~-1!
- if !Size4! GEQ 40 set /a size4=!size4!-!Size4:~-1!
- if !Size2! LEQ 39 set /a size2=!size2!-1
- if !Size3! LEQ 39 set /a size3=!size3!-1
- if !Size4! LEQ 39 set /a size4=!size4!-1
- if !size1! GEQ 0 (set size1=!size1!G) else set "size1= "
- if !size2! GEQ 0 (set size2=!size2!G) else set "size2= "
- if !size3! GEQ 0 (set size3=!size3!G) else set "size3= "
- if !size4! GEQ 0 (set size4=!size4!G) else set "size4= "
-
- ::获取IP等信息及WMIC取显卡、声卡型号
- for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:"IP Address"') do set IP=%%i
- for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:"Subnet Mask"') do set Subnet=%%i
- for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:"Physical Address"') do set mac=%%i
- for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:"Default Gateway"') do set gateway=%%i
- for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:"DNS Servers"') do set dns=%%i
- for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:"Description"') do set netcard=%%i
- for /f "skip=1 delims=" %%i in ('wmic SOUNDDEV get ProductName') do set SOUND=%%i
- for /f "tokens=1,2 delims==" %%a in ('wmic path Win32_VideoController get AdapterRAM^,Name /value^|findstr "AdapterRAM Name"') do set Video=%%b
-
- ::输出到文件并清除临时文件
- echo.>>!file!
- echo 计算机名: !computername!>>!file!
- echo 主机型号: !XH!>>!file!
- echo CPU 相关: !CPU!>>!file!
- echo 内存总量: !mem!>>!file!
- if not "!HDD1!"=="" echo 硬盘1型号: !HDD1:~0,-2!>>!file!
- if not "!HDD1!"=="" echo 硬盘1容量: !size1!>>!file!
- if not "!HDD2!"=="" echo 硬盘2型号: !HDD2:~0,-2!>>!file!
- if not "!HDD2!"=="" echo 硬盘2容量: !size2!>>!file!
- if not "!HDD3!"=="" echo 硬盘3型号: !HDD3:~0,-2!>>!file!
- if not "!HDD3!"=="" echo 硬盘3容量: !size3!>>!file!
- if not "!HDD4!"=="" echo 硬盘4型号: !HDD4:~0,-2!>>!file!
- if not "!HDD4!"=="" echo 硬盘4容量: !size4!>>!file!
- echo 声卡型号: !SOUND!>>!file!
- echo 显卡型号: !Video!>>!file!
- echo 网卡型号: !netcard!>>!file!
- echo MAC 地址: !mac!>>!file!
- echo I P 地址: !IP!>>!file!
- echo 子网掩码: !Subnet!>>!file!
- echo 网 关: !gateway!>>!file!
- echo D N S : !dns!>>!file!
- echo.>>!file!
- echo.>>!file!
- echo 下面是DXDIAG生成的信息。>>!file!
- echo.>>!file!
- type !txt!>>!file!
-
- del /f !txt!
- exit
复制代码
|