ProcessStartInfo.UseShellExecute Propriedade
Definição
Obtém ou define um valor que indica se o shell do sistema operacional deve ser usado para iniciar o processo.Gets or sets a value indicating whether to use the operating system shell to start the process.
public:
property bool UseShellExecute { bool get(); void set(bool value); };
public bool UseShellExecute { get; set; }
member this.UseShellExecute : bool with get, set
Public Property UseShellExecute As Boolean
Valor da propriedade
true caso o shell deva ser usado ao iniciar o processo. false caso o processo deva ser criado diretamente do arquivo executável.true if the shell should be used when starting the process; false if the process should be created directly from the executable file. O padrão é true em aplicativos .NET Framework e false em aplicativos .NET Core.The default is true on .NET Framework apps and false on .NET Core apps.
Exceções
Uma tentativa de definir o valor como true ocorre em aplicativos UWP (Plataforma Universal do Windows).An attempt to set the value to true on Universal Windows Platform (UWP) apps occurs.
Exemplos
// Run "cl.exe /cld stdstr.cpp /link /out:sample.exe". 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 cl.exe is directed to the Process.StandardOutput stream
// which is then displayed in this console window directly.
Process^ compiler = gcnew Process;
compiler->StartInfo->FileName = "cl.exe";
compiler->StartInfo->Arguments = "/clr stdstr.cpp /link /out:sample.exe";
compiler->StartInfo->UseShellExecute = false;
compiler->StartInfo->RedirectStandardOutput = true;
compiler->Start();
Console::WriteLine( compiler->StandardOutput->ReadToEnd() );
compiler->WaitForExit();
// Run "csc.exe /r:System.dll /out:sample.exe stdstr.cs". 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.
using (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();
}
' 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.
Using 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()
End Using
Comentários
Definir essa propriedade para false permitir que você redirecione fluxos de entrada, saída e erro.Setting this property to false enables you to redirect input, output, and error streams.
A palavra "Shell" neste contexto ( UseShellExecute ) refere-se a um shell gráfico (semelhante ao shell do Windows) em vez de shells de comando (por exemplo, bash ou sh ) e permite que os usuários iniciem aplicativos gráficos ou abram documentos.The word "shell" in this context (UseShellExecute) refers to a graphical shell (similar to the Windows shell) rather than command shells (for example, bash or sh) and lets users launch graphical applications or open documents.
Observação
UseShellExecute deve ser false se a UserName propriedade não for null ou uma cadeia de caracteres vazia, ou uma InvalidOperationException será gerada quando o Process.Start(ProcessStartInfo) método for chamado.UseShellExecute must be false if the UserName property is not null or an empty string, or an InvalidOperationException will be thrown when the Process.Start(ProcessStartInfo) method is called.
Ao usar o Shell do sistema operacional para iniciar processos, você pode iniciar qualquer documento (que é qualquer tipo de arquivo registrado associado a um executável que tenha uma ação aberta padrão) e executar operações no arquivo, como a impressão, usando o Process objeto.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. Quando UseShellExecute é false , você pode iniciar somente executáveis usando o Process objeto.When UseShellExecute is false, you can start only executables by using the Process object.
Observação
UseShellExecute deve ser true se você definir a ErrorDialog propriedade como true .UseShellExecute must be true if you set the ErrorDialog property to true.
Se você definir WindowStyle como ProcessWindowStyle.Hidden , UseShellExecute deve ser definido como true .If you set the WindowStyle to ProcessWindowStyle.Hidden, UseShellExecute must be set to true.
WorkingDirectoryWorkingDirectory
A WorkingDirectory propriedade se comporta de forma diferente, dependendo do valor da UseShellExecute propriedade.The WorkingDirectory property behaves differently depending on the value of the UseShellExecute property. Quando UseShellExecute é true , a WorkingDirectory propriedade especifica o local do executável.When UseShellExecute is true, the WorkingDirectory property specifies the location of the executable. Se WorkingDirectory for uma cadeia de caracteres vazia, supõe-se que o diretório atual contém o executável.If WorkingDirectory is an empty string, it is assumed that the current directory contains the executable.
Quando UseShellExecute é false , a WorkingDirectory propriedade não é usada para localizar o executável.When UseShellExecute is false, the WorkingDirectory property is not used to find the executable. Em vez disso, ele é usado apenas pelo processo que é iniciado e tem significado apenas dentro do contexto do novo processo.Instead, it is used only by the process that is started and has meaning only within the context of the new process. Quando UseShellExecute é false , a FileName propriedade pode ser um caminho totalmente qualificado para o executável ou um nome executável simples que o sistema tentará localizar em pastas especificadas pela variável de ambiente Path.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.