我正在尝试获取My Installer脚本的系统信息。这是我的简单批处理脚本。
@echo off
setlocal enableextensions enabledelayedexpansion
echo System information now loading...
for /f "delims=" %%l in ('wmic os get * /format:list') do >nul 2>&1 set "OS_%%l"
for /f "delims=" %%l in ('wmic cpu get * /format:list') do >nul 2>&1 set "CPU_%%l"
set /a FreeSpace=0
for /f "skip=1 tokens=1,2" %%A in ('wmic logicaldisk get FreeSpace') do (
if "%%B" neq "" for /f %%N in ('powershell !FreeSpace!+%%A') do (
set FreeSpace=%%N
)
)
echo wsh.echo cdbl(%FreeSpace%)/1024/1024/1024 > %temp%.\tmp.vbs
for /f %%a in ('cscript //nologo %temp%.\tmp.vbs') do set /a HDD_FreeSpace=%%a
del %temp%.\tmp.vbs
set /a RAM_Memory=%OS_TotalVisibleMemorySize%/1024
set /a CPU_Speed=%CPU_NumberOfLogicalProcessors%*%CPU_CurrentClockSpeed%
>>SystemInfo.log 2>&1 echo Operating System: %OS_Caption%%OS_OSArchitecture% (%OS_Version%, Build %OS_BuildNumber%)
>>SystemInfo.log 2>&1 echo Processor: %CPU_Name%
>>SystemInfo.log 2>&1 echo RAM: %RAM_Memory% MB
>>SystemInfo.log 2>&1 echo HDD Total Free Space: %HDD_FreeSpace% GB
>>SystemSource.log 2>&1 echo %OS_Version%
>>SystemSource.log 2>&1 echo %CPU_Speed%
>>SystemSource.log 2>&1 echo %OS_TotalVisibleMemorySize%
>>SystemSource.log 2>&1 echo %FreeSpace%
exit
输出SystemInfo.log
Operating System: Microsoft Windows 7 Professional 32-bit (6.1.7601, Build 7601)
Processor: Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz
RAM: 3069 MB
HDD Total Free Space: 61 GB
输出SystemSource.log
6.1.7601
4784
3143284
66427858944
一切似乎都很好。但批处理脚本显示“缺少运算符”,我不知道为什么显示消息但所有输出都是正确的。
它会崩溃吗?
答案 0 :(得分:5)
带走@echo off
。您会看到设置/一个HDD_FreeSpace = 375.6279296875 的行集。期间无效
c:\>for /F %a in ('cscript //nologo C:\Users\PREET~1.SAN\AppData\Local\Temp.\tmp.vbs') do set /a HDD_FreeSpace=%a
c:\>set /a HDD_FreeSpace=375.625617980957
Missing operator.
c:\>del C:\Users\PREET~1.SAN\AppData\Local\Temp.\tmp.vbs
尝试使用* SET * 而不是