Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i was trying to write a batch file that installs a program, and when there is an error return the error level - except when it has errorlevel 3010
@echo off
:SP2
Start /wait C:\SQLInstall\SP2\SQLServer2005SP2-KB921896-x86-ENU.exe /quiet /allinstances
IF (%ERRORLEVEL% == 0) goto OK
else IF (%ERRORLEVEL% == 3010) goto Restart
else goto ERROR_SP2Install:OK
echo SP2 Installation finished.
echo Log file for SQL 2005 SP2:
echo C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\Log\Hotfix\Summary.txt
echo.:Restart
echo SP2 Installation finished. Restart required.
echo Log file for SQL 2005 SP2:
echo C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\Log\Hotfix\Summary.txt
echo.:ERROR_SP2Install
echo Error occurs when installating SQL server 2005 SP2. Error level: %ERRORLEVEL%
echo Log file for SQL 2005 SP2:
echo C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\Log\Hotfix\Summary.txthowever this doesnt works. Could anyone please help me to come up with a way that I can get the errorlevel when there is an error except when it was errorlevel 3010?

Hi Razor,
Thanks for your help, and I have tried with your suggestion. In your suggestion it will always go to ERROR_SP2Install no matter what the errorlevel is, but my intension is going to ERROR_SP2Install only when there is a errorlevel > 0 and not 3010.To illustrate clearer:
Case 1: errorlevel = 0
then OK
Case 2: errorlevel = 3010
then prompt for reboot
Case 3: all other errorlevel
then return the errorlevel valueis there anyway to do this, or if there is any Case command that i can use in Batch file?

Razor, I think an exe file always returns an errorlevel, although if it doesn't set it explicitly it may be random.
Since the original poster says that it always goes to ERROR_SP2Install, this means that his program is always returning an errorlevel other than 0 or 3010.
nic829, have you tried inserting echo %errorlevel% just before the goto commands that Razor gave you, to see exactly what error level you are getting?

Razor, I think an exe file always returns an errorlevel, although if it doesn't set it explicitly it may be random.
You would think, but START is a built-in, and not an actual program. I seem to remember it doing some funky things with errorlevel, but I could be wrong.

I think the problem is START.
Presumably, START succeeds and sets 0.
Worse yet, using START the bat goes on it's way and doesn't care what the exe is doing. I see no need for START.
=====================================
If at first you don't succeed, you're about average.M2

The START/WAIT command is presumably there to pause the batch file until the executable it invokes returns. Otherwise, it will run the executable and the batch will continue running concurrently. When I tried it, START forwarded the errorlevel returned by the executable.

Thanks you all, but I dont think the problem is caused by the start.
So i've tried Razor's method:
IF %ERRORLEVEL%==0 goto OK
IF %ERRORLEVEL%==3010 goto Restart
goto ERROR_SP2InstallNormally my batch should return an errorlevel 3010, and therefore should be going to this: IF (%ERRORLEVEL% == 3010) goto Restart
however it never goes. Instead it directly goes to this: goto ERROR_SP2InstallIs it in batch file we cannot do the If-Then-else thing?

Could you please add the following line just before these IF statements, and post your results here.
echo Actual errorlevel is %ERRORLEVEL%

"Thanks you all, but I dont think the problem is caused by the start."
LOL
easy to find out
=====================================
If at first you don't succeed, you're about average.M2

I think it actually is going to Restart. But you think that it is not. That's because you haven't got a "goto :end" at the end of each labelled section, and therefore the flow of control falls through from Restart to ERROR_SP2Install.

"falls through"
yep, that'll do it
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |