Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
UseShellExecute Property

ProcessStartInfo.UseShellExecute Property

Gets or sets a value indicating whether to use the operating system shell to start the process.

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

'Declaration
<MonitoringDescriptionAttribute("ProcessUseShellExecute")> _
Public Property UseShellExecute As Boolean

Property Value

Type: System.Boolean
true if the shell should be used when starting the process; false if the process should be created directly from the executable file. The default is true.

Setting this property to false enables you to redirect input, output, and error streams.

NoteNote

   UseShellExecute must be false if the UserName property is not Nothing or an empty string, or an InvalidOperationException will be thrown when the Process.Start(ProcessStartInfo) method is called.

When you use the operating system shell to start processes, you can start any document (which is any registered file type associated with an executable that has a default open action) and perform operations on the file, such as printing, by using the Process object. When UseShellExecute is false, you can start only executables by using the Process object.

NoteNote

UseShellExecute must be true if you set the ErrorDialog property to true.

The WorkingDirectory property behaves differently depending on the value of the UseShellExecute property. When UseShellExecute is true, the WorkingDirectory property specifies the location of the executable. If WorkingDirectory is an empty string, it is assumed that the current directory contains the executable.

When UseShellExecute is false, the WorkingDirectory property is not used to find the executable. Instead, it is used only by the process that is started and has meaning only within the context of the new process. When UseShellExecute is false, the FileName property can be either a fully qualified path to the executable, or a simple executable name that the system will attempt to find within folders specified by the PATH environment variable.

' Run "vbc.exe /reference:Microsoft.VisualBasic.dll /out:sample.exe stdstr.vb". UseShellExecute is False  
' because we're specifying an executable directly and in this case depending on it being in a PATH folder.  
' By setting RedirectStandardOutput to True, the output of csc.exe is directed to the Process.StandardOutput  
' stream which is then displayed in this console window directly.     
Dim compiler As New Process()
compiler.StartInfo.FileName = "vbc.exe"
compiler.StartInfo.Arguments = "/reference:Microsoft.VisualBasic.dll /out:sample.exe stdstr.vb"
compiler.StartInfo.UseShellExecute = False
compiler.StartInfo.RedirectStandardOutput = True
compiler.Start()

Console.WriteLine(compiler.StandardOutput.ReadToEnd())

compiler.WaitForExit()

.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