使用WMIC / APPEND获取PC规格

时间:2018-10-26 10:59:45

标签: batch-file cmd

@echo off
whoami > "%~dp0%computername%_%username%.txt"
WMIC /APPEND:"%~dp0%computername%_%username%.txt" BIOS Get Manufacturer,Name /Format:table
WMIC /APPEND:"%~dp0%computername%_%username%.txt" Baseboard Get Product,Manufacturer /Format:table
WMIC /APPEND:"%~dp0%computername%_%username%.txt" CPU Get Name,NumberOfCores,NumberOfLogicalProcessors /Format:table
WMIC /APPEND:"%~dp0%computername%_%username%.txt" Memorychip Get Manufacturer,Capacity,Speed,PartNumber /Format:table
WMIC /APPEND:"%~dp0%computername%_%username%.txt" Diskdrive Get Model,Size /Format:table
WMIC /APPEND:"%~dp0%computername%_%username%.txt" Path Win32_VideoController get Caption,VideoModeDescription /Format:table
WMIC /APPEND:"%~dp0%computername%_%username%.txt" OS get Caption,OSArchitecture,Version /Format:table
WMIC /APPEND:"%~dp0%computername%_%username%.txt" netuse get Name /Format:table 
pause

除了OS的字符串外,其他所有方法都运行良好:只能看到“ Caption OSArchitecture Version”,但在CMD中,我可以看到脚本显示了

Caption                              OSArchitecture         Version
Microsoft Windows 10 Pro  64-bit  10.0.17134

如何使脚本不删除该字符串?

1 个答案:

答案 0 :(得分:0)

有时,WMIC的Unicode输出本身有点太聪明了。通过FIND运行所有程序会将其转换为本地代码页。

@echo off
SET "OUTFILE=%~dp0%computername%_%username%.txt"
IF EXIST "%OUTFILE%" (DEL "%OUTFILE%")

(
whoami
WMIC BIOS Get Manufacturer,Name /Format:table
WMIC Baseboard Get Product,Manufacturer /Format:table
WMIC CPU Get Name,NumberOfCores,NumberOfLogicalProcessors /Format:table
WMIC Memorychip Get Manufacturer,Capacity,Speed,PartNumber /Format:table
WMIC Diskdrive Get Model,Size /Format:table
WMIC Path Win32_VideoController get Caption,VideoModeDescription /Format:table
WMIC OS get Caption,OSArchitecture,Version /Format:table
WMIC netuse get Name /Format:table
) | FIND /V "" >>"%OUTFILE%"