Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

ProcessStartInfo.UseShellExecute Property

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

[Visual Basic]
Public Property UseShellExecute As Boolean
[C#]
public bool UseShellExecute {get; set;}
[C++]
public: __property bool get_UseShellExecute();
public: __property void set_UseShellExecute(bool);
[JScript]
public function get UseShellExecute() : Boolean;
public function set UseShellExecute(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.

Remarks

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

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.

Note    UseShellExecute must be true if you set ErrorDialog 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.

Example

[Visual Basic] 
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()

[C#] 
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();

[C++] 
Process* compiler = new Process();
compiler->StartInfo->FileName = S"cl.exe";
compiler->StartInfo->Arguments = S"/clr stdstr.cpp /link /out:sample.exe";
compiler->StartInfo->UseShellExecute = false;
compiler->StartInfo->RedirectStandardOutput = true;
compiler->Start();

Console::WriteLine(compiler->StandardOutput->ReadToEnd());

compiler->WaitForExit();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ProcessStartInfo Class | ProcessStartInfo Members | System.Diagnostics Namespace | RedirectStandardInput | RedirectStandardOutput | RedirectStandardError

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.