Environment.CommandLine Environment.CommandLine Environment.CommandLine Environment.CommandLine Property

定義

取得這個處理程序的命令列。Gets the command line for this process.

public:
 static property System::String ^ CommandLine { System::String ^ get(); };
public static string CommandLine { get; }
member this.CommandLine : string
Public Shared ReadOnly Property CommandLine As String

屬性值

含有命令列引數的字串。A string containing command-line arguments.

範例

下列範例會顯示它自己的命令列。The following example displays its own command line.

using namespace System;

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

C:\>env0 ARBITRARY TEXT

CommandLine: env0 ARBITRARY TEXT
*/
using System;

class Example
{
    public static void Main() 
    {
       Console.WriteLine();
       //  Invoke this sample with an arbitrary set of command line arguments.
       Console.WriteLine("CommandLine: {0}", Environment.CommandLine);
    }
}
// The example displays output like the following:
//       C:\>env0 ARBITRARY TEXT
//       
//       CommandLine: env0 ARBITRARY TEXT
Class Example
   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 
End Class 
' The example displays output like the following:
'       C:\>CommandLine ARBITRARY TEXT
'       
'       CommandLine: CommandLine ARBITRARY TEXT

備註

此屬性可存取的程式名稱和目前的處理序啟動時,在命令列上指定任何引數。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 include path information, but is not required to do so. 使用GetCommandLineArgs剖析方法來擷取命令列的資訊,並儲存在陣列中的字串。Use the GetCommandLineArgs method to retrieve the command-line information parsed and stored in an array of strings.

指定的數字的字元; 未設定的命令列的緩衝區大小上限Windows 作業系統的電腦上執行而有所不同。The maximum size of the command-line buffer is not set to a specific number of characters; it varies depending on the Windows operating system that is running on the computer.

安全性

EnvironmentPermission
針對至 PATH 環境變數的讀取權限。for read access to the PATH environment variable. 相關聯的列舉型別: ReadAssociated enumeration: Read

適用於

另請參閱