MSIexec Not setting %ERRORLEVEL% even when using START

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
julesverne
Posts: 81
Joined: 19 Nov 2013 00:41

MSIexec Not setting %ERRORLEVEL% even when using START

#1 Post by julesverne » 02 Dec 2013 11:07

I'm testing this bat file from 2 different locations. One from my desktop in a folder called "Testing Area". The other location is on the root directory of a thumb drive. I'm testing the 2nd IF %ERRORLEVEL% statement by not including the installer in the same path as the bat file so that it will give me an error code greater than 0. But it doesn't. It stays at 0.

According to this http://blogs.msdn.com/b/heaths/archive/2005/11/15/493236.aspx?Redirected=true I should get an updated %ERRORLEVEL% after msiexec is executed from the script using the Start /WAIT command. It isn't working for me. Can someone help me understand why and how I can fix it?


Here's my code.

Code: Select all

@echo off
 
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
 
REG.exe Query %RegQry% > checkOS.txt
 
Find /i "x86" < CheckOS.txt > StringCheck.txt
 
If %ERRORLEVEL% == 0 (
    Set OSVersion=32bit
) ELSE (
    Set OSVersion=64bit
)

del checkOS.txt
del StringCheck.txt

:INSTALLTIGHTVNC
ECHO installing and setting up VNC on computer.
IF %OSVersion% == 32bit (
   START /WAIT "TIGHTVNC" msiexec /qb /norestart /i tightvnc-2.7.10-setup-32bit.msi ADDLOCAL="Server,Viewer" SET_USEVNCAUTHENTICATION=1 VALUE_OF_USEVNCAUTHENTICATION=1 SET_PASSWORD=1 VALUE_OF_PASSWORD=xxx SET_CONTROLPASSWORD=5
   IF %ERRORLEVEL% NEQ 0 (
      START "Download Installer" "http://www.tightvnc.com/download/2.7.10/tightvnc-2.7.10-setup-32bit.msi"
      echo x=MSGBOX ("Either you have the wrong tightvnc installer or it's not on your thumbdrive. This BAT file is opening up a browser to the correct installer.  Please save it to your thumbdrive in the same directory as your batch file.",0,"TightVNC Install is Completed!"^) > %temp%\TEMPmessage.vbs
      call %temp%\TEMPmessage.vbs
      del %temp%\TEMPmessage.vbs /f /q
      SET /P READY=PRESS ENTER WHEN READY TO RETRY INSTALLING TIGHTVNC
      GOTO :INSTALLTIGHTVNC
      )
) ELSE (
   START /WAIT "TIGHTVNC" msiexec /qb /norestart /i tightvnc-2.7.10-setup-64bit.msi ADDLOCAL="Server,Viewer" SET_USEVNCAUTHENTICATION=1 VALUE_OF_USEVNCAUTHENTICATION=1 SET_PASSWORD=1 VALUE_OF_PASSWORD=xxx SET_CONTROLPASSWORD=5
   IF %ERRORLEVEL% NEQ 0 (
      START "Download Installer" "http://www.tightvnc.com/download/2.7.10/tightvnc-2.7.10-setup-64bit.msi"
      echo x=MSGBOX ("Either you have the wrong tightvnc installer or it's not on your thumbdrive. This BAT file is opening up a browser to the correct installer.  Please save it to your thumbdrive in the same directory as your batch file.",0,"TightVNC Install is Completed!"^) > %temp%\TEMPmessage.vbs
      call %temp%\TEMPmessage.vbs
      del %temp%\TEMPmessage.vbs /f /q
      SET /P READY=PRESS ENTER WHEN READY TO RETRY INSTALLING TIGHTVNC
      GOTO :INSTALLTIGHTVNC
      )
)

echo x=MSGBOX ("Installation and Configuration of TightVNC is done on this %OSVersion% version of Windows.",0,"TightVNC Install is Completed!"^) > %temp%\TEMPmessage.vbs

call %temp%\TEMPmessage.vbs
del %temp%\TEMPmessage.vbs /f /q

EXIT

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: MSIexec Not setting %ERRORLEVEL% even when using START

#2 Post by carlos » 02 Dec 2013 19:17

Hello. I not read all the code. But you have to use delayed expansion of errorlevel environment variable and be sure of do the comprobation inmediately after the command, else you can get a overwrited errorlevel. Other option is use if errorlevel that means greater or equal. For convert the expresion use two if errorlevel like this: for check a errorlevel equal to 5: if errorlevel 5 if not errorlevel 6

julesverne
Posts: 81
Joined: 19 Nov 2013 00:41

Re: MSIexec Not setting %ERRORLEVEL% even when using START

#3 Post by julesverne » 02 Dec 2013 21:25

Hi Carlos. Unfortunately, that didn't work. Still returns 0 as if nothing went wrong with the install. :?

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: MSIexec Not setting %ERRORLEVEL% even when using START

#4 Post by carlos » 03 Dec 2013 09:10

try use this in the head:

replace:

Code: Select all

@echo off


by:

Code: Select all

@echo off
SetLocal EnableExtensions EnableDelayedExpansion


and replace the two lines:

Code: Select all

   IF %ERRORLEVEL% NEQ 0 (


by:

Code: Select all

   IF !ERRORLEVEL! NEQ 0 (

julesverne
Posts: 81
Joined: 19 Nov 2013 00:41

Re: MSIexec Not setting %ERRORLEVEL% even when using START

#5 Post by julesverne » 03 Dec 2013 11:44

That worked Carlos! Thanks! :D

Post Reply