Export (0) Print
Expand All

Environment.CommandLine Property

Gets the command line for this process.

[Visual Basic]
Public Shared ReadOnly Property CommandLine As String
[C#]
public static string CommandLine {get;}
[C++]
public: __property static String* get_CommandLine();
[JScript]
public static function get CommandLine() : String;

Property Value

A string containing command line arguments.

Remarks

This property provides access to the program name and any arguments specified on the command line when the current process was started.

The program name can, but is not required to, include path information. Use the GetCommandLineArgs method to retrieve the command line information parsed and stored in an array of strings.

Windows NT 4.0, Windows 2000 Platform Note:  The name of the executable file does not include the path.

Windows 98, Windows Millennium Edition Platform Note:  The name of the executable file includes the path. Long file names (non-8dot3 names) can be shortened to their 8dot3 representation.

Example

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

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      '  Invoke this sample with an arbitrary set of command line arguments.
      Console.WriteLine("CommandLine: {0}", Environment.CommandLine)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'C:\>CommandLine ARBITRARY TEXT
'
'CommandLine: CommandLine ARBITRARY TEXT
'

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

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine();
//  Invoke this sample with an arbitrary set of command line arguments.
    Console.WriteLine("CommandLine: {0}", Environment.CommandLine);
    }
}
/*
This example produces the following results:

C:\>env0 ARBITRARY TEXT

CommandLine: env0 ARBITRARY TEXT
*/

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

using namespace System;

int main() {
   Console::WriteLine();
   //  Invoke this sample with an arbitrary set of command line arguments.
   Console::WriteLine(S"CommandLine: {0}", Environment::CommandLine);
}
/*
This example produces the following results:

C:\>env0 ARBITRARY TEXT

CommandLine: env0 ARBITRARY TEXT
*/

[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

.NET Framework Security: 

See Also

Environment Class | Environment Members | System Namespace | GetCommandLineArgs

Show:
© 2015 Microsoft