我正在尝试将我的安装批处理文件仅在我安装的当前版本比本地计算机上安装的版本(如果安装的话)更新的情况下运行。我一直在环顾四周,似乎常见的方法是写入注册表,然后通过检查它是否存在以及值来使用该条目来关键,以便将来关键。
我在此网站上发现此FOR statement,它将检查注册表项是否等于特定值,但我希望查询能够确定注册表值是否小于指定值。是HKLM ...... \ Installed_Reg_Key值(即4.5)小于5.0。如果我必须有两个IF语句,一个用于检查密钥是否存在(如果它当前未安装),另一个用于检查它是否小于我正在推送的那个,那很好。如果我必须编写特定类型的reg密钥,我可能会更少关注。
谢谢, 布赖恩
答案 0 :(得分:1)
见下面的代码 -
您只需要一个FOR语句来测试 - 因为它将填充一个环境变量。如果该变量不存在,则表示未安装该程序,并且您:调用适当的操作。
以下代码:
@echo off SETLOCAL ENABLEEXTENSIONS SETLOCAL ENABLEDELAYEDEXPANSION 设置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