ProcessStartInfo.UseShellExecute Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee wordt een waarde opgehaald of ingesteld die aangeeft of de shell van het besturingssysteem moet worden gebruikt om het proces te starten.
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
Waarde van eigenschap
true als de shell moet worden gebruikt bij het starten van het proces; false als het proces rechtstreeks vanuit het uitvoerbare bestand moet worden gemaakt. De standaardwaarde is false (of true in .NET Framework-apps).
Uitzonderingen
Er wordt geprobeerd de waarde in te stellen op true op Universal Windows Platform (UWP)-apps.
Voorbeelden
// 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
Opmerkingen
De ProcessStartInfo klasse geeft een set waarden op die worden gebruikt wanneer u een proces start.
Door de UseShellExecute-eigenschap in te stellen, kunt u invoer-, uitvoer- en foutstromen omleiden door false.
Het woord 'shell' in deze context (UseShellExecute) verwijst naar een grafische shell (vergelijkbaar met de Windows-shell) in plaats van opdrachtshells (bijvoorbeeld bash of sh) en stelt gebruikers in staat grafische toepassingen te starten of documenten te openen.
Note
UseShellExecute moet false zijn als de UserName eigenschap niet null of een lege tekenreeks is, anders wordt er een InvalidOperationException geworpen wanneer de Process.Start(ProcessStartInfo) methode wordt aangeroepen.
Wanneer u de shell van het besturingssysteem gebruikt om processen te starten, kunt u elk document (dat elk geregistreerd bestandstype is dat is gekoppeld aan een uitvoerbaar bestand met een standaardactie openen) starten en bewerkingen uitvoeren op het bestand, zoals afdrukken, met behulp van het Process object. Wanneer UseShellExecute is false, kunt u alleen uitvoerbare bestanden starten met behulp van het Process object.
Note
UseShellExecute moet zijn true als u de ErrorDialog eigenschap instelt op true.
WorkingDirectory
De WorkingDirectory eigenschap gedraagt zich anders, afhankelijk van de waarde van de UseShellExecute eigenschap. Wanneer UseShellExecute is true, geeft de WorkingDirectory eigenschap de locatie van het uitvoerbare bestand op. Als WorkingDirectory dit een lege tekenreeks is, wordt ervan uitgegaan dat de huidige map het uitvoerbare bestand bevat.
Wanneer UseShellExecute is false, wordt de WorkingDirectory eigenschap niet gebruikt om het uitvoerbare bestand te vinden. In plaats daarvan wordt het alleen gebruikt door het proces dat wordt gestart en alleen betekenis heeft binnen de context van het nieuwe proces. Wanneer UseShellExecutefalse is, kan de FileName-eigenschap zijn een volledig pad naar het uitvoerbare bestand of een eenvoudige bestandsnaam van het uitvoerbare bestand die het systeem probeert te vinden in de mappen die staan aangegeven door de PATH-omgevingsvariabele. De interpretatie van het zoekpad is afhankelijk van het besturingssysteem. Voer HELP PATH of man sh in bij een opdrachtprompt voor meer informatie.