Reputation: 137
I'm trying to get my install batch file to only run if the current version I'm installing is newer than the version installed on the local machine (if installed at all). I've been looking around and it seems like the common approach is to write to the registry, and then use that entry to key off for the future, by checking to see if it's there and the value.
I found this FOR statement here on this site that will check to see if a registry key equals a particular value, but I want the query to be able to determine if the registry value is less than a specified value. Is HKLM......\Installed_Reg_Key value (which is 4.5) less than 5.0. If I have to have two IF statements, one to check to see if the key is there (if it's not currently installed) and another to check to see if it's less than what I'm pushing, that's fine. And if I have to write a particular type of reg key, I could care less.
Thanks, Brian
Upvotes: 1
Views: 2955
Reputation: 444
See code below -
You just need a single FOR statement to test - as it will populate an environment variable. If the variable does not exist, then the program is not installed, and you :CALL an appropriate action.
The code below:
@echo off SETLOCAL ENABLEEXTENSIONS SETLOCAL ENABLEDELAYEDEXPANSION set batchver=
for /f "tokens=3 skip=3" %%i in ('reg query HKLM\Software\batchver /v batchver') do @set batchver=%%i if .batchver==. call :new_install :: if already installed do nothing. if batchver==5.0 @echo Up to date! && goto :exit if batchver leq 4.5 call :reinstall if batchver gte 4.6 call :patch goto :exit :new_install <new installation routines here.> ::update registry with new version reg add HKLM\software\batchver /v batchver /d 5.0 /f goto :eof :reinstall <reinstall routine here> ::update registry with new version reg add HKLM\software\batchver /v batchver /d 5.0 /f goto :eof :patch <patch routines here> ::update registry with new version reg add HKLM\software\batchver /v batchver /d 5.0 /f goto :eof :exit
Upvotes: 1