Take the 2-minute tour ×  I am trying to set and get the
application exit code .  I am trying to do something following :
protected override void OnStartup(StartupEventArgs e)      if (
e.Args.Length != 0)          new MainWindow().ShowDialog();
Environment.ExitCode = 110;  And then I am trying in cmd to get
it by echo %ERRORLEVEL%  But I get always result 0 , any idea
what is the issue ?  share|improve this question try out
ERRORLEVEL without percent sign –  sll Oct 14 '11 at 18:36 @sll
, this way i get result ERRORLEVEL –  Night Walker Oct 14 '11 at
18:38  6 Answers 6  up vote 8 down vote accepted  For WPF, try
Note that the application needs to be running as a console app.
This answer is the easiest way I know of; the accepted answer
looks more difficult.  An easy test to tell if you're running in
console mode: call your app from the command line (make sure
your code doesn't shut down right away). The main window should
be showing. If you can type another command in the console, your
app is not runn