有一个问题,我似乎无法使下面的脚本工作。基本上作为总结,我需要确保应用程序的版本大于2.0.0.8
所以这是我的代码:
setlocal enabledelayedexpansion
set n2=2.0.0.8
FOR /F "tokens=2* delims=0 " %%A IN ('REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall
\FB58E75BC1D58DF60340894DB00D3FA9BBD513B6" /v displayversion') DO SET n1=%%B
IF %n1% GEQ %n2% (goto success) else (goto error)
:success
start notepad.exe
Goto:eof
:error
start winword.exe
Goto:eof
:eof
exit
输出工作正常,n1使用记事本和winword启动纯粹作为测试输出大于2.0.0.8的版本(输出2.0.0.12)。
无论它总是出现什么错误并打开Winword.exe
测试中的值是2.0.0.12,为什么这仍然是错误的?
希望这是有道理的
由于
米高扬
答案 0 :(得分:2)
尝试删除这些点,以便将它们作为小数进行比较:
setlocal enabledelayedexpansion
set n2=2.0.0.8
FOR /F "tokens=2* delims=0 " %%A IN (
'REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\FB58E75BC1D58DF60340894DB00D3FA9BBD513B6" /v displayversion'
) DO SET n1=%%B
for /f "tokens=1,2,3,4 delims=." %%a in ("%n2%") do set "v2=%%a%%b%%c%%d"
for /f "tokens=1,2,3,4 delims=." %%a in ("%n1%") do set "v1=%%a%%b%%c%%d"
IF %v1% GEQ %v2% (goto success) else (goto error)
答案 1 :(得分:0)
setlocal enabledelayedexpansion
set n2=2.0.0.8
FOR /F "tokens=2* delims=0 " %%A IN ('REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\FB58E75BC1D58DF60340894DB00D3FA9BBD513B6" /v displayversion') DO SET n1=%%B
for /f "tokens=1,2,3,4 delims=." %%a in ("%n2%") do set "v2=%%a%%b%%c%%d"
for /f "tokens=1,2,3,4 delims=." %%a in ("%n1%") do set "v1=%%a%%b%%c%%d"
IF %v1% GEQ %v2% (goto success) else (goto error)