ProcessStartInfo.ArgumentList Property

Definition

Gets a collection of command-line arguments to use when starting the application. Strings added to the list don't need to be previously escaped.

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)

Property Value

A collection of command-line arguments.

Examples

This example adds three arguments to the process start info.

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"""

Remarks

ArgumentList and the Arguments property are independent of one another and only one of them can be used at the same time. The main difference between both APIs is that ArgumentList takes care of escaping the provided arguments and internally builds a single string that is passed to operating system when calling Process.Start(info). So if you are not sure how to properly escape your arguments, you should choose ArgumentList over Arguments.

Important

Using an instance of this object with untrusted data is a security risk. Use this object only with trusted data. For more information, see Validate All Inputs.

Applies to