Mikoyan
Mikoyan

Reputation: 59

Reg Query Batch File

To summarise what I want to achieve, I want to query 2 keys, if they exist go to end of batch file, if not install Java.

The batch file is installing Java fine, but when testing if I delete the .txt file:

IF exist %windir%\gpologs\jre_1.7.21.x86.txt goto eof ELSE goto Q1

The installer still tried to install over the top, even though one of the registry keys exists?

Here is full batch file:

IF exist %windir%\grouppolicylogs\jre_1.7.21.x86.txt goto eof ELSE goto Q1

:Q1 
Reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F86417025FF}" 
if %ErrorLevel% EQU == 0 goto End ELSE goto Q2

:Q2 
Reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F83217021FF}" 
if %ErrorLevel% EQU == 0 goto End ELSE goto Install 

:Install 
msiexec /i "\\servername\SoftwareRep\Java\Java 1.7.0_21 x86\jre1.7.0_21.msi" /qn
if %ErrorLevel% EQU 0 (
  >>"\\servername\gpolog\jre_1.7.21.x86.csv" echo "%computername%","%date%","%Time%","%ErrorLevel%","Java Runtime 1.7.0_21x86 Installed"
  >>"%windir%\GpoLogs\jre_1.7.21.x86.txt" echo "Java Runtime 1.7.0_21x86 Installed"
) else (
  >>"\\servername\gpolog\JavaInstallErrors.csv" echo "%computername%","%date%","%Time%","%ErrorLevel%","Error trying to install Java 1.7_21x86"
)

:END 

Where am I going wrong?

Upvotes: 0

Views: 8455

Answers (1)

David Ruhmann
David Ruhmann

Reputation: 11367

Use only one equals operator. Not both EQU and ==

if "%ErrorLevel%"=="0" goto End ELSE goto Q2

if "%ErrorLevel%"=="0" goto End ELSE goto Install

Scope your if statement commands

if "%ErrorLevel%"=="0" ( goto End ) ELSE ( goto Q2 )

if "%ErrorLevel%"=="0" ( goto End ) ELSE ( goto Install )

The eof needs a colon unless you have a eof label.

goto :eof

See if /?

See goto /?

Upvotes: 1

Related Questions