Reputation: 3
I am trying to install the latest version of some software via a batch file. Each version has a unique string value so I would like to install the latest version only if the value in the registry is not of the latest version.
The following is part of my batch file:
reg query HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall{731F6BAA-A986-45A4-8936-7C3AAAAA760B} /f 1.3.0.13565 if %ErrorLevel% EQU 0 goto INSTALL if %ErrorLevel% EQU 1 goto END
The issue is that this does not work. The string name is DisplayVersion
but if I type in if %DisplayVersion% EQU 1.3.0.13565
this doesn't work either. Perhaps I shouldn't be using ErrorLevel
? Is it possible to say if DisplayVersion equals to 1.3.0.13565 then GOTO INSTALL else END
?
EDIT:
My batch file now looks like this:
@%SystemRoot%\System32\reg.exe Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760B}" /F "1.3.0.13565" /Reg:32 1> NUL 2>&1 || Exit /B
:INSTALL
msiexec /x {731F6BAA-A986-45A4-8936-7C3AAAAA760B} /q
msiexec /i "\\appserve01\share$\Teams\Teams_x64_13028779.msi" ALLUSER=1
:END
Upvotes: 0
Views: 462
Reputation: 38579
The following line should be sufficient to perform everything your question requested.
%SystemRoot%\System32\reg.exe Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760B}" /F "1.3.0.13565" /Reg:32 1> NUL 2>&1 && (GoTo INSTALL) || GoTo END
I don't think it is necessary to make it any more robust, unless you really think that it is possible that the string 1.3.0.13565
could exist elsewhere in the values or data under that key.
Upvotes: 2