@Echo OFF set newline=^& echo. echo Manufacturer Information> test1.txt systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" >>test1.txt echo cpu Information:>> test1.txt wmic cpu get Name /Format:list >> test1.txt echo %newline%Process Information:>> test1.txt wmic computersystem get NumberofProcessors /Format:list >> test1.txt echo %newline%NIC Information:>> test1.txt wmic nicconfig where "IPEnabled=TRUE" get ipaddress,macaddress,defaultipgateway /format:list >>test1.txt
输出看起来:
Manufacturer Information Host Name: DK-IT OS Name:
Microsoft Windows 8.1 Single Language System Model:
Inspiron 7537 System Type: x64-based PC Total Physical
Memory: 6,043 MB cpu Information:06001
2 d : 2 0 8 8 : 8 b a 1 ” } M A C A d d r e s s = 0 C : 8 B : F D
: 9 C : 8 0 : 4 706002
C 0 : 0 0 : 0 1
D e f a u l t I P G a t e w a y = I P A d d r e s s = { ” 1 9 2
. 1 6 8 . 1 9 0 . 1 ”,” f e 8 0 : : 6 4 b 2 : 2 a a a : e f 6 4 : f
a 9 a ” } M A C A d d r e s s = 0 0 : 5 0 : 5 6 : C 0 : 0 0 : 0 8
1)将WMIC输出管道传输到MORE
更多将Unicode转换为ANSII.我还将结果传递给FINDSTR以消除空行.该解决方案的唯一问题是具有转换的怪癖导致WMIC输出在每行的末尾具有额外的回车(< CR>< CR>< LF>而不是< CR>< LF>)
@echo OFF >test1.txt ( echo Manufacturer Information: systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" echo( echo cpu Information: wmic cpu get Name /Format:list | more | findstr . wmic computersystem get NumberofProcessors /Format:list | more | findstr . echo( echo NIC Information: wmic nicconfig where IPEnabled=TRUE get ipaddress,defaultipgateway /format:list | more | findstr . )
——————————
其余的解决方案都经过适当的格式化,没有任何额外的< CR>
临时文件采用Unicode格式,TYPE正确地将Unicode转换为ANSII.我仍然将结果传递给FINDSTR以消除空行.
@echo OFF >test2.txt ( echo Manufacturer Information: systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" echo( echo cpu Information: call :wmic cpu get Name /Format:list call :wmic computersystem get NumberofProcessors /Format:list echo( echo NIC Information: call :wmic nicconfig where IPEnabled=TRUE get ipaddress,defaultipgateway /format:list ) exit /b :wmic wmic %* >test.tmp type test.tmp | findstr . del test.tmp exit /b
3)通过两个FOR / F循环运行WMIC.
第一个FOR / F将WMIC输出转换为ANSII,但它具有额外的< CR>在每一行的末尾.第二个FOR / F剥离不想要的尾随< CR>. FOR / F自动剥离空白行.
@echo OFF >test3.txt ( echo Manufacturer Information: systeminfo|findstr /c:"Host Name" /c:"OS Name" /c:"System Model:" /c:"System Type:" /c:"Total Physical Memory:" echo( echo cpu Information: call :wmic cpu get Name /Format:list call :wmic computersystem get NumberofProcessors /Format:list echo( echo NIC Information: call :wmic nicconfig where IPEnabled=TRUE get ipaddress,defaultipgateway /format:list ) exit /b :wmic for /f "delims=" %%A in ('"wmic %*"') do for /f "delims=" %%B in ("%%A") do echo %%B exit /b