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")
{
    ArgumentList = {
        "/c",
        "dir",
        @"C:\Program Files\dotnet" // The space character is escaped automatically.
    }
};

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

注解

ArgumentList 并且属性 Arguments 彼此独立, 并且只能同时使用其中一个属性。 这些 API 之间的主要区别在于, ArgumentList 转义所提供的参数, 并在内部 生成在调用 Process.Start(info)时传递给操作系统的单个字符串。 因此,如果不确定如何正确转义参数,则应选择ArgumentListArguments

Important

将此类型的实例用于不受信任的数据是一种安全风险。 仅将此对象与受信任的数据一起使用。 有关详细信息,请参阅验证所有输入

适用于