Q:

Can we capture the error in batch script when some command shows window errors?

I faced one problem. Am installing some software through batch script. My script file is below
msiexec /i "d:\ffr\ff\ff.msi"  /qb /NORESTART  
echo %errorlevel% 

Here the file d:\ffr\ff\ff.msi not exist in my system so it showing a new window with error message "The installation package could not be opened. Verify that package exists and that you can access it, or contact the application vendor.... "
Then next line echo %errorlevel%  o/p is 0.
we may do this like 
IF EXIST "d:\ffr\ff\ff.msi" (msiexec /i "d:\ffr\ff\ff.msi"  /qb /NORESTART  )

But my need to catch that error message or any information that something went wrong in my batch file. Is there any way ?  Thank you. 

A:

So in as a solution, you can only print the error or other text with it purely if ERRORLEVEL is bigger than 0
@echo off
SETLOCAL EnableDelayedExpansion
ver > nul
msiexec /i "d:\ffr\ff\ff.msi"  /qb /QUIET /NORESTART
if ERRORLEVEL == 1 echo There was a problem with the command error returned %errorlevel%

