%ERRORLEVEL% might be what you want to look into