Go to End in Batch file

Alex
Alex used Ask the Experts™
on
Morning,

So I have this code which people helped me with, i'm just trying to get it to skip the installation if a reg key exists.

@echo off
setlocal enabledelayedexpansion

set GUIDs=DDF96E66-E39B-4A69-B776-2DE49EBCAFBD D7D3F00A-638B-41DE-A2A3-FFC6EF034783 B1A6CB20-C032-4228-940F-AC3BC9BF6B3E 3EB41C0B-00EF-4C8B-9FF7-FF252E2F4E33 D8A08493-2F06-4EB2-A636-4392991981AB 
for %%a in (%GUIDs%) do (
     reg.exe query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{%%a}" >NUL 2>&1
      if not errorlevel 1 (
            echo Uninstalling %%a
          msiexec.exe /X{%%a} /quiet
      )
)

:::8x8 VOD Latest Version Installation
::: Copy the latest version of the VOD to the path below and change the msi filename

Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{5FCB2176-11C5-4114-889B-CD93066BE094}
IF %errorlevel%==0 GOTO END


msiexec.exe /i "\\domain.com\SYSVOL\domain.com\scripts\8x8\VOD_5_6_0.msi" /qn
                (if %errorlevel%==0 (
                  echo %date% %time% %Computername% - Installation succeeded
)              ELSE (
                                echo %date% %time% %Computername% - Installation FAILED - %errorlevel%
)) >>      "\\file08\W common\logs\%Computername% InstallVOD.log""
::: Please wait for the time to finish

timeout 15

:END

Open in new window


The bit I've got issues with is

Reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{5FCB2176-11C5-4114-889B-CD93066BE094}
IF %errorlevel%==0 GOTO END

And then the :END label, it doesn't seem to work quite right.

Is it right or am I missing something?

Thanks
Alex
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Should work, but there is no need to define a label "end". There is an implicitly defined label ":eof" that you can use as "goto :eof".
Try it like that:
@echo off
setlocal enabledelayedexpansion

set GUIDs=DDF96E66-E39B-4A69-B776-2DE49EBCAFBD D7D3F00A-638B-41DE-A2A3-FFC6EF034783 B1A6CB20-C032-4228-940F-AC3BC9BF6B3E 3EB41C0B-00EF-4C8B-9FF7-FF252E2F4E33 D8A08493-2F06-4EB2-A636-4392991981AB 
for %%a in (%GUIDs%) do (
	reg.exe query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{%%a}" >NUL 2>&1
	if not errorlevel 1 (
		echo Uninstalling %%a
		msiexec.exe /X{%%a} /quiet
	)
)

:::8x8 VOD Latest Version Installation
::: Copy the latest version of the VOD to the path below and change the msi filename
reg.exe query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{5FCB2176-11C5-4114-889B-CD93066BE094}" >NUL 2>&1
if not errorlevel 1 (
	echo 8x8 VOD Latest Version is already installed, leaving.
	goto :eof
)

msiexec.exe /i "\\domain.com\SYSVOL\domain.com\scripts\8x8\VOD_5_6_0.msi" /qn
(
	if %errorlevel%==0 (
		echo %date% %time% %Computername% - Installation succeeded
	) else (
		echo %date% %time% %Computername% - Installation FAILED - %errorlevel%
	)
) >> "\\file08\W common\logs\%Computername% InstallVOD.log""
::: Please wait for the time to finish

timeout 15

Open in new window

AlexSenior Infrastructure Analyst

Author

Commented:
What's that bit here

>NUL 2>&1
if not errorlevel 1 (
      echo 8x8 VOD Latest Version is already installed, leaving.
      goto :eof
)

The nul bit?

Thanks
Alex
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
The ">NUL" redirects the standard output of reg.exe to the NUL device, that is, suppresses it, since you're not really interested in the value, just whether the key exists.
The "2>&1" redirects the error output (if the key wasn't found) to the standard output (which is already suppressed), suppressing it as well.
AlexSenior Infrastructure Analyst

Author

Commented:
Excellent, thank you again, I thought I'd got pretty close but I love your reporting.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial