我正在寻找一种更清洁的方法来做到这一点。我很确定这是错误的,即使它有点工作。基本上我从文件(temp.txt)中获取这样的输出:
Host Name: IBM-3J93A46MRS5
OS Name: Microsoft Windows 7 Professional
OS Version: 6.1.7631 Service Pack 1 Build 7601
OS Configuration: Standalone Workstation
Registered Owner: IAMADMIN
Original Install Date: 2011-12-15, 10:56:07 AM
System Boot Time: 2013-05-27, 9:55:36 AM
System Manufacturer: DELL
System Model: 4009BF7
Time Zone: (UTC-05:00) Eastern Time (US & Canada)
Total Physical Memory: 16,316 MB
Available Physical Memory: 11,356 MB
并试图将第二列数据放入变量中。取决于我要不要。我正在使用 Findstr 来清除。
@echo off
setlocal enabledelayedexpansion
systeminfo > temp.txt
set "tmp_result_file=temp.txt"
for /f "tokens=3-7 delims= " %%i in ('FINDSTR /C:"OS Name:" %tmp_result_file%') do set "OSNAME=%%i %%j %%k %%l"
for /f "tokens=3-10 delims= " %%i in ('FINDSTR /V /C:"BIOS Version:" %tmp_result_file%^|FIND /I "OS Version:"') do set "OSVER=%%i %%j %%k %%l %%m %%n %%o %%p"
for /f "tokens=4-7 delims= " %%i in ('FINDSTR /C:"Original Install Date:" %tmp_result_file%') do set "INSTDATE=%%i %%j %%k %%l"
for /f "tokens=3-7 delims= " %%i in ('FINDSTR /C:"System Manufacturer:" %tmp_result_file%') do set "SYSMFG=%%i %%j %%k %%l"
for /f "tokens=3-7 delims= " %%i in ('FINDSTR /C:"System Model:" %tmp_result_file%') do set "SYSMDL=%%i %%j %%k %%l"
echo.
echo Operating System : %OSNAME% , %OSVER%
echo Original Install Date : %INSTDATE%
echo Model Information : %SYSMFG% %SYSMDL%
我不喜欢如此精确地使用令牌,我只需要搜索值之后的所有内容。