This documentation is archived and is not being maintained.

Environment.ExitCode Property

Gets or sets the exit code of the process.

[Visual Basic]
Public Shared Property ExitCode As Integer
[C#]
public static int ExitCode {get; set;}
[C++]
public: __property static int get_ExitCode();
public: __property static void set_ExitCode(int);
[JScript]
public static function get ExitCode() : int;
public static function set ExitCode(int);

Property Value

A 32-bit signed integer containing the exit code. The default value is zero.

Remarks

This property can be used to return a success code from an application. For example, it can be used to control the execution of a set of applications invoked in a script. If the value of this property is not set by an application, zero is returned.

[C++] The system exit code is set to the return value of the function, main, or zero if main returns void, regardless of whether the user sets this property.

Example

[Visual Basic] 
' Sample for the Environment.ExitCode property
Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("ExitCode: {0}", Environment.ExitCode)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'ExitCode: 0
'

[C#] 
// Sample for the Environment.ExitCode property
using System;

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine();
    Console.WriteLine("ExitCode: {0}", Environment.ExitCode);
    }
}
/*
This example produces the following results:

ExitCode: 0
*/

[C++] 
// Sample for the Environment::ExitCode property
#using <mscorlib.dll>

using namespace System;

int main() {
   Console::WriteLine();
   Console::WriteLine(S"ExitCode: {0}", __box(Environment::ExitCode));
}
/*
This example produces the following results:

ExitCode: 0
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

Environment Class | Environment Members | System Namespace

Show: