ProcessStartInfo.ArgumentList 屬性

定義

取得啟動應用程式時要使用的命令列引數集合。 新增至清單的字串無須先行逸出。

public:
 property System::Collections::ObjectModel::Collection<System::String ^> ^ ArgumentList { System::Collections::ObjectModel::Collection<System::String ^> ^ get(); };
public System.Collections.ObjectModel.Collection<string> ArgumentList { get; }
member this.ArgumentList : System.Collections.ObjectModel.Collection<string>
Public ReadOnly Property ArgumentList As Collection(Of String)

屬性值

命令行自變數的集合。

範例

此範例會將三個自變數新增至進程開始資訊。

var info = new System.Diagnostics.ProcessStartInfo("cmd.exe");
info.ArgumentList.Add("/c");
info.ArgumentList.Add("dir");
info.ArgumentList.Add(@"C:\Program Files\dotnet"); // there is no need to escape the space, the API takes care of it

// or if you prefer collection property initializer syntax:

var info = new System.Diagnostics.ProcessStartInfo("cmd.exe")
{
    ArgumentList = {
        "/c",
        "dir",
        @"C:\Program Files\dotnet"
    }
};

// The corresponding assignment to the Arguments property is:

var info = new System.Diagnostics.ProcessStartInfo("cmd.exe")
{
    Arguments = "/c dir \"C:\\Program Files\\dotnet\""
};
Dim info As New System.Diagnostics.ProcessStartInfo("cmd.exe")
info.ArgumentList.Add("/c")
info.ArgumentList.Add("dir")
info.ArgumentList.Add("C:\Program Files\dotnet")

' The corresponding assignment to the Arguments property is:

info.Arguments = "/c dir ""C:\Program Files\dotnet"""

備註

ArgumentListArguments和 屬性彼此無關,而且只能同時使用其中一個。 這兩個 API 之間的主要差異在於負責 ArgumentList 逸出提供的自變數,並在 內部 建置在呼叫 Process.Start(info)時傳遞至操作系統的單一字串。 因此,如果您不確定如何正確逸出自變數,您應該選擇 ArgumentList 而非 Arguments

重要

使用此物件的執行個體時,若並用了不信任的資料,會造成安全性上的風險。 使用此物件時,請一律使用信任的資料。 如需詳細資訊,請參閱 驗證所有輸入

適用於