I am currently working on a WPF Application which is providing
ErrorLevel is NOT 0
The program ' MyApp.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program ' MyApp.vshost.exe' has exited with code 3 (0x3).
=> returns 0
I'm not 100% sure but it could be related to how you might be invoking the EXE in your script. To mimic your situation, I created a simple WPF application that immediately exits via
Environment.Exit(3); and then a simple
@echo off start /wait TestApp.exe echo %ERRORLEVEL%
What was echoed was in fact
Update: I noticed that the ERRORLEVEL is not properly set if
start is used without the
/wait option. I believe this is due to the fact that
start will not wait for the application to exit before continuing. Therefore you can use
start /wait TestApp.exe or simply
call TestApp.exe. I have updated the example above.