ProcessStartInfo.UseShellExecute Propiedad

Definición

Obtiene o establece un valor que indica si se va a usar el shell del sistema operativo para iniciar el proceso.

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 de propiedad

true si se debe usar el shell al iniciar el proceso; false si el proceso se debe crear directamente desde el archivo ejecutable. El valor predeterminado es false (o true en aplicaciones de .NET Framework).

Excepciones

Se produce un intento de establecer el valor en true en Plataforma universal de Windows (UWP) aplicaciones.

Ejemplos

// 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

Comentarios

La ProcessStartInfo clase especifica un conjunto de valores que se usan al iniciar un proceso.

Establecer la UseShellExecute propiedad en false le permite redirigir flujos de entrada, salida y error.

La palabra "shell" en este contexto (UseShellExecute) hace referencia a un shell gráfico (similar al shell de Windows) en lugar de a shells de comandos (por ejemplo, bash o sh) y permite a los usuarios iniciar aplicaciones gráficas o abrir documentos.

Note

UseShellExecute debe ser false si la propiedad UserName no es null ni una cadena vacía, o se lanzará una InvalidOperationException cuando el método Process.Start(ProcessStartInfo) sea llamado.

Al usar el shell del sistema operativo para iniciar procesos, puede iniciar cualquier documento (que sea cualquier tipo de archivo registrado asociado a un archivo ejecutable que tenga una acción abierta predeterminada) y realizar operaciones en el archivo, como imprimir, mediante el Process objeto . Cuando UseShellExecute es false, solo puede iniciar ejecutables mediante el Process objeto .

Note

UseShellExecute debe ser true si establece la propiedad ErrorDialog en true.

WorkingDirectory

La WorkingDirectory propiedad se comporta de forma diferente en función del valor de la UseShellExecute propiedad. Cuando UseShellExecute es true, la WorkingDirectory propiedad especifica la ubicación del ejecutable. Si WorkingDirectory es una cadena vacía, se supone que el directorio actual contiene el ejecutable.

Cuando UseShellExecute es false, la WorkingDirectory propiedad no se usa para buscar el archivo ejecutable. En su lugar, solo lo usa el proceso que se inicia y solo tiene significado dentro del contexto del nuevo proceso. Cuando UseShellExecute es false, la FileName propiedad puede ser una ruta de acceso completa al ejecutable o un nombre ejecutable simple que el sistema intentará buscar dentro de las carpetas especificadas por la variable de entorno PATH. La interpretación de la ruta de búsqueda depende del sistema operativo. Para obtener más información, escriba HELP PATH o man sh en un símbolo del sistema.

Se aplica a

Consulte también