我使用下面的命令提取了“chrome.exe”版本。我想获取与提取的版本相比的值。
setlocal enableDelayedExpansion
FOR /F "tokens=2 delims==" %%I IN (
'wmic datafile where "name='C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'" get version /format:list'
) DO FOR /F "delims=" %%A IN ("%%I") DO SET "ChromeVersion=%%A"
if version=94.0.4606.71
如果高于版本值,我想退出。
if %ChromeVersion%==higher goto end
如果低于版本值则安装。
if %ChromeVersion%==lower goto install
答案1
@echo off
for /f usebackq^tokens^=3 %%i in (
`reg query HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon /v version`
)do set "_current=%%~i"
set "_version=94.0.4606.71"
set "_current=%_current:.=%0000000"
if %_current:~0,9% lss %_version:.=% (
goto :install )else goto :eOf
你不需要使用 doublefor
来做到这一点,因此不需要使用setlocal enableDelayedExpansion
进一步阅读:
答案2
谢谢您的帮助。我已经实施了我想要的操作。
set ChromeDeploryVersion=94.0.4606.71
for /f usebackq^tokens^=3 %%i in (
`reg query HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon /v version`
)do set "_current=%%~i"
echo.
echo The current version of Chrome is %_current%
echo.
set "_version=%ChromeDeploryVersion%"
if %_current%==%ChromeDeploryVersion% goto VersionSame
set "_current=%_current:.=%0000000"
if %_current:~0,9% lss %_version:.=% (
goto :install) else (goto :HighVersion
)
:VersionSame
echo.
echo.
echo ▶ Chrome version is same.
echo.
echo.
goto end
:install
echo.
echo.
echo ▶ Chrome version is low.
echo.
echo.
goto end
:HighVersion
echo.
echo.
echo ▶ Chrome version is high.
echo.
echo.
goto end