Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ProcessStartInfo.Arguments Property

Gets or sets the set of command-line arguments to use when starting the application.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)

[MonitoringDescriptionAttribute("ProcessArguments")]
[SettingsBindableAttribute(true)]
[TypeConverterAttribute("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Arguments { get; set; }

Property Value

Type: System.String
A single string containing the arguments to pass to the target application specified in the FileName property. The default is an empty string (""). On Windows Vista and earlier versions of the Windows operating system, the length of the arguments added to the length of the full path to the process must be less than 2080. On Windows 7 and later versions, the length must be less than 32699.
Arguments are parsed and interpreted by the target application, so must align with the expectations of that application. For.NET applications as demonstrated in the Examples below, spaces are interpreted as a separator between multiple arguments. A single argument that includes spaces must be surrounded by quotation marks, but those quotation marks are not carried through to the target application. In include quotation marks in the final parsed argument, triple-escape each mark.

The first example below creates a small application (argsecho.exe) that echos its arguments to the console. The second example creates an application that invokes argsecho.exe to demonstrate different variations for the Arguments property.

// 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 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);
        }
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft