Process.StartInfo Property

Definition

Gets or sets the properties to pass to the Start() method of the Process.

public:
 property System::Diagnostics::ProcessStartInfo ^ StartInfo { System::Diagnostics::ProcessStartInfo ^ get(); void set(System::Diagnostics::ProcessStartInfo ^ value); };
public System.Diagnostics.ProcessStartInfo StartInfo { get; set; }
[System.ComponentModel.Browsable(false)]
public System.Diagnostics.ProcessStartInfo StartInfo { get; set; }
member this.StartInfo : System.Diagnostics.ProcessStartInfo with get, set
[<System.ComponentModel.Browsable(false)>]
member this.StartInfo : System.Diagnostics.ProcessStartInfo with get, set
Public Property StartInfo As ProcessStartInfo

Property Value

The ProcessStartInfo that represents the data with which to start the process. These arguments include the name of the executable file or document used to start the process.

Attributes

Exceptions

The value that specifies the StartInfo is null.

.NET Core and .NET 5+ only: The Start() method was not used to start the process.

Examples

The following example populates a StartInfo with the file to execute, the action performed on it and whether it should displays a user interface. For additional examples, refer to the reference pages for properties of the ProcessStartInfo class.

#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

int main()
{
    Process^ myProcess = gcnew Process;

    try
    {
        myProcess->StartInfo->UseShellExecute = false;
        // You can start any process, HelloWorld is a do-nothing example.
        myProcess->StartInfo->FileName = "C:\\HelloWorld.exe";
        myProcess->StartInfo->CreateNoWindow = true;
        myProcess->Start();
        // This code assumes the process you are starting will terminate itself. 
        // Given that it is started without a window so you cannot terminate it 
        // on the desktop, it must terminate itself or you can do it programmatically
        // from this application using the Kill method.
    }
    catch ( Exception^ e ) 
    {
        Console::WriteLine( e->Message );
    }
}
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        public static void Main()
        {
            try
            {
                using (Process myProcess = new Process())
                {
                    myProcess.StartInfo.UseShellExecute = false;
                    // You can start any process, HelloWorld is a do-nothing example.
                    myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
                    myProcess.StartInfo.CreateNoWindow = true;
                    myProcess.Start();
                    // This code assumes the process you are starting will terminate itself.
                    // Given that it is started without a window so you cannot terminate it
                    // on the desktop, it must terminate itself or you can do it programmatically
                    // from this application using the Kill method.
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}
open System.Diagnostics

try
    use myProcess = new Process()
    myProcess.StartInfo.UseShellExecute <- false
    // You can start any process, HelloWorld is a do-nothing example.
    myProcess.StartInfo.FileName <- @"C:\HelloWorld.exe"
    myProcess.StartInfo.CreateNoWindow <- true
    myProcess.Start() |> ignore
// This code assumes the process you are starting will terminate itself.
// Given that it is started without a window so you cannot terminate it
// on the desktop, it must terminate itself or you can do it programmatically
// from this application using the Kill method.
with e ->
    printfn $"{e.Message}"
Imports System.Diagnostics
Imports System.ComponentModel

Namespace MyProcessSample
    Class MyProcess
        Public Shared Sub Main()
            Try
                Using myProcess As New Process()

                    myProcess.StartInfo.UseShellExecute = False
                    ' You can start any process, HelloWorld is a do-nothing example.
                    myProcess.StartInfo.FileName = "C:\\HelloWorld.exe"
                    myProcess.StartInfo.CreateNoWindow = True
                    myProcess.Start()
                    ' This code assumes the process you are starting will terminate itself. 
                    ' Given that it is started without a window so you cannot terminate it 
                    ' on the desktop, it must terminate itself or you can do it programmatically
                    ' from this application using the Kill method.
                End Using
            Catch e As Exception
                Console.WriteLine((e.Message))
            End Try
        End Sub
    End Class
End Namespace

Remarks

StartInfo represents the set of parameters to use to start a process. When Start is called, the StartInfo is used to specify the process to start. The only necessary StartInfo member to set is the FileName property. Starting a process by specifying the FileName property is similar to typing the information in the Run dialog box of the Windows Start menu. Therefore, the FileName property does not need to represent an executable file. It can be of any file type for which the extension has been associated with an application installed on the system. For example the FileName can have a .txt extension if you have associated text files with an editor, such as Notepad, or it can have a .doc if you have associated .doc files with a word processing tool, such as Microsoft Word. Similarly, in the same way that the Run dialog box can accept an executable file name with or without the .exe extension, the .exe extension is optional in the FileName member. For example, you can set the FileName property to either "Notepad.exe" or "Notepad".

You can start a ClickOnce application by setting the FileName property to the location (for example, a Web address) from which you originally installed the application. Do not start a ClickOnce application by specifying its installed location on your hard drive.

If the file name involves a nonexecutable file, such as a .doc file, you can include a verb specifying what action to take on the file. For example, you could set the Verb to "Print" for a file ending in the .doc extension. The file name specified in the FileName property does not need to have an extension if you manually enter a value for the Verb property. However, if you use the Verbs property to determine what verbs are available, you must include the extension.

You can change the parameters specified in the StartInfo property up to the time that you call the Start method on the process. After you start the process, changing the StartInfo values does not affect or restart the associated process. If you call the Start(ProcessStartInfo) method with the ProcessStartInfo.UserName and ProcessStartInfo.Password properties set, the unmanaged CreateProcessWithLogonW function is called, which starts the process in a new window even if the CreateNoWindow property value is true or the WindowStyle property value is Hidden.

You should only access the StartInfo property on a Process object returned by the Start method. For example, you should not access the StartInfo property on a Process object returned by GetProcesses. Otherwise, on .NET Core the StartInfo property will throw an InvalidOperationException and on .NET Framework it will return a dummy ProcessStartInfo object.

When the process is started, the file name is the file that populates the (read-only) MainModule property. If you want to retrieve the executable file that is associated with the process after the process has started, use the MainModule property. If you want to set the executable file of a Process instance for which an associated process has not been started, use the StartInfo property's FileName member. Because the members of the StartInfo property are arguments that are passed to the Start method of a process, changing the FileName property after the associated process has started will not reset the MainModule property. These properties are used only to initialize the associated process.

Applies to

See also