ProcessStartInfo.Arguments Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit l’ensemble d’arguments de ligne de commande à utiliser lors du démarrage de l’application.
public:
property System::String ^ Arguments { System::String ^ get(); void set(System::String ^ value); };
public string Arguments { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Arguments { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Arguments { get; set; }
[System.ComponentModel.SettingsBindable(true)]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Arguments { get; set; }
[System.ComponentModel.SettingsBindable(true)]
public string Arguments { get; set; }
member this.Arguments : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Arguments : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Arguments : string with get, set
[<System.ComponentModel.SettingsBindable(true)>]
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Arguments : string with get, set
[<System.ComponentModel.SettingsBindable(true)>]
member this.Arguments : string with get, set
Public Property Arguments As String
Valeur de propriété
Chaîne unique contenant les arguments à passer à l’application cible spécifiée dans la FileName propriété. La valeur par défaut est une chaîne vide ( » « ).
- Attributs
Exemples
Le premier exemple crée une petite application (argsecho.exe) qui fait écho à ses arguments à la console. Le deuxième exemple crée une application qui appelle argsecho.exe pour illustrer différentes variantes de la Arguments propriété.
// Place this code into a console project called ArgsEcho to build the argsecho.exe target
using System;
namespace StartArgs
{
class ArgsEcho
{
static void Main(string[] args)
{
Console.WriteLine("Received the following arguments:\n");
for (var i = 0; i < args.Length; i++)
{
Console.WriteLine($"[{i}] = {args[i]}");
}
Console.WriteLine("\nPress any key to exit");
Console.ReadLine();
}
}
}
' Place this code into a console project called ArgsEcho to build the argsecho.exe target
Module Module1
Sub Main()
Dim i As Integer = 0
For Each s As String In My.Application.CommandLineArgs
Console.WriteLine($"[{i}] = {s}")
i = i + 1
Next
Console.WriteLine(Environment.NewLine + "Press any key to exit")
Console.ReadLine()
End Sub
End Module
// Place this code into a console project called StartArgsEcho. It depends on the
// console application named argsecho.exe.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace StartArgsEcho
{
class Program
{
static void Main()
{
ProcessStartInfo startInfo = new ProcessStartInfo("argsecho.exe");
startInfo.WindowStyle = ProcessWindowStyle.Normal;
// Start with one argument.
// Output of ArgsEcho:
// [0]=/a
startInfo.Arguments = "/a";
Process.Start(startInfo);
// Start with multiple arguments separated by spaces.
// Output of ArgsEcho:
// [0] = /a
// [1] = /b
// [2] = c:\temp
startInfo.Arguments = "/a /b c:\\temp";
Process.Start(startInfo);
// An argument with spaces inside quotes is interpreted as multiple arguments.
// Output of ArgsEcho:
// [0] = /a
// [1] = literal string arg
startInfo.Arguments = "/a \"literal string arg\"";
Process.Start(startInfo);
// An argument inside double quotes is interpreted as if the quote weren't there,
// that is, as separate arguments. Equivalent verbatim string is @"/a /b:""string with quotes"""
// Output of ArgsEcho:
// [0] = /a
// [1] = /b:string
// [2] = in
// [3] = double
// [4] = quotes
startInfo.Arguments = "/a /b:\"\"string in double quotes\"\"";
Process.Start(startInfo);
// Triple-escape quotation marks to include the character in the final argument received
// by the target process. Equivalent verbatim string: @"/a /b:""""""quoted string""""""";
// [0] = /a
// [1] = /b:"quoted string"
startInfo.Arguments = "/a /b:\"\"\"quoted string\"\"\"";
Process.Start(startInfo);
}
}
}
' Place this code into a console project called StartArgsEcho. It depends on the
' console application named argsecho.exe.
Module Module1
Sub Main()
Dim startInfo As ProcessStartInfo = New ProcessStartInfo("argsecho.exe")
startInfo.WindowStyle = ProcessWindowStyle.Normal
' Start with one argument.
' Output of ArgsEcho:
' [0]=/a
startInfo.Arguments = "/a"
Process.Start(startInfo)
' Start with multiple arguments separated by spaces.
' Output of ArgsEcho:
' [0] = /a
' [1] = /b
' [2] = c:\temp
startInfo.Arguments = "/a /b c:\temp"
Process.Start(startInfo)
' An argument with spaces inside quotes is interpreted as multiple arguments.
' Output of ArgsEcho:
' [0] = /a
' [1] = literal string arg
startInfo.Arguments = "/a ""literal string arg"" "
Process.Start(startInfo)
' An argument inside double quotes is interpreted as if the quote weren't there,
' that is, as separate arguments.
' Output of ArgsEcho:
' [0] = /a
' [1] = /b:string
' [2] = in
' [3] = double
' [4] = quotes
startInfo.Arguments = "/a /b:""""string in double quotes"""" "
Process.Start(startInfo)
' Triple-escape quotation marks to include the character in the final argument received
' by the target process.
' [0] = /a
' [1] = /b:"quoted string"
startInfo.Arguments = "/a /b:""""""quoted string"""""" "
Process.Start(startInfo)
End Sub
End Module
Remarques
La longueur de la chaîne affectée à la Arguments propriété doit être inférieure à 32 699.
Les arguments sont analysés et interprétés par l’application cible. Ils doivent donc s’aligner sur les attentes de cette application. Pour les applications .NET comme illustré dans les exemples ci-dessous, les espaces sont interprétés comme un séparateur entre plusieurs arguments. Un seul argument qui inclut des espaces doit être entouré de guillemets, mais ces guillemets ne sont pas transmis à l’application cible. Pour inclure des guillemets dans l’argument analysé final, double échappement chaque marque. Si vous utilisez cette propriété pour définir des arguments de ligne de commande, ArgumentList ne doit contenir aucun élément.
Arguments et ArgumentList sont indépendants les uns des autres. Autrement dit, la chaîne affectée à la Arguments propriété ne remplit pas la ArgumentList collection et les membres de la ArgumentList collection ne sont pas affectés à la Arguments propriété.
Important
L’utilisation d’une instance de ce type avec des données non approuvées est un risque de sécurité. Utilisez cet objet uniquement avec des données approuvées. Pour plus d’informations, consultez Valider toutes les entrées.