0

Having an issue whereby I cannot seem to make the following script work. Basically as a summary I need to ensure a version of an application is greater than 2.0.0.8

So here is my code:

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

The output works fine and n1 outputs a version greater than 2.0.0.8 (it output 2.0.0.12) using notepad and winword launching purely as testing.

No matter what it always errors and opens Winword.exe

The value in testing is 2.0.0.12 so why is this still erroring out?

Hope this makes sense

Thanks

Mikoyan

Mikoyan
  • 59
  • 2
  • 8

2 Answers2

2

Try to remove the dots so you'll compare them as decimals:

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)
npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • 2
    I'm afraid this works only if the respective numeric parts have got the same number of digits... – aschipfl Jul 21 '16 at 14:37
  • 1
    Thanks you all for directing me on the correct path, managed to solve this with all of your help and great thanks to npocmaka! – Mikoyan Jul 21 '16 at 16:36
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)
Mikoyan
  • 59
  • 2
  • 8