Link to home
Start Free TrialLog in
Avatar of TimAllan
TimAllanFlag for Australia

asked on

Return error code from a fail/successful batch file

I've got a batch file that I'm running under SCCM 2007 that installs the Cisco VPN Client and determines whether or not it's 32 bit or 64 bit.  That part works fine.

However, I'd like it to return a 0 error code for success or error code 1 >= if it fails at any stage.  At the moment it just returns an error code of 0 so it's telling me it's always successful in SCCM.  

Below is the batch file script :


Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% > checkOS.txt
Find /i "x86" < CheckOS.txt > StringCheck.txt
If %ERRORLEVEL% == 0 (
msiexec /i 32bit\vpnclient_setup.msi LAUNCHSETMTU=0 /norestart /qn
) ELSE (
msiexec /i 64bit\vpnclient_setup.msi LAUNCHSETMTU=0 /norestart /qn
)
del checkos.txt /q
del stringcheck.txt /q

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of TechnoChat
TechnoChat
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Qlemo
You can force an errorlevel by using exit. That is, if msiexec returns an error status at all. Else you would need some checking code, e.g. whether one of the required files or reg keys exist after installation.
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% | Find /i "x86" && (
msiexec /i 32bit\vpnclient_setup.msi LAUNCHSETMTU=0 /norestart /qn
) ELSE (
msiexec /i 64bit\vpnclient_setup.msi LAUNCHSETMTU=0 /norestart /qn
)
exit /b %errorlevel%

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TimAllan

ASKER

Thanks guys, I used a bit from each of your responses for my solution. great work.
And what about my solution? Ok, I forgot to replace ELSE by ||, but besides that, I cannot see any disadvantages in your case. BTW, it could be optimized more, by only setting the base bath to 32bit or 64bit, and use that in a single command after, which makes it really neat, and doesn't need an exit. The same can be done by checking %PROCESSOR_ARCHITECTURE%, as shown in the first comment.
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% | Find /i "x86" >nul && (
  set base=32bit
) || (
  set base=64bit
)
msiexec /i %base%\vpnclient_setup.msi LAUNCHSETMTU=0 /norestart /qn

Open in new window