Export (0) Print
Expand All

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)

public bool UseShellExecute { get; set; }
/** @property */
public boolean get_UseShellExecute ()

/** @property */
public void set_UseShellExecute (boolean value)

public function get UseShellExecute () : boolean

public function set UseShellExecute (value : boolean)

Property Value

true to use the shell when starting the process; otherwise, the process is 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 a null reference (Nothing in Visual Basic) 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 are able to 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, with the Process component. When UseShellExecute is false, you are able to start only executables with the Process component.

NoteNote

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

The WorkingDirectory property behaves differently when UseShellExecute is true than when UseShellExecute is false. When UseShellExecute is true, the WorkingDirectory property specifies the location of the executable. If WorkingDirectory is an empty string, the current directory is understood to contain the executable.

When UseShellExecute is false, the WorkingDirectory property is not used to find the executable. Instead, it is used by the process that is launched and only has meaning within the context of the new process.

Process compiler = new Process();
compiler.StartInfo.FileName = "csc.exe";
compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();    

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

compiler.WaitForExit();

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft