ProcessStartInfo.UseShellExecute プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
プロセスの起動にオペレーティング システムのシェルを使用するかどうかを示す値を取得または設定します。
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
プロパティ値
プロセスを起動するときにシェルを使用する場合は true
。プロセスを実行可能ファイルから直接作成する場合は false
。 既定値は、true
.NET Framework アプリと false
.NET Core アプリです。
例外
ユニバーサル Windows プラットフォーム (UWP) アプリで値を true
に設定することが試みられます。
例
// 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
注釈
このプロパティを設定すると false
、入力ストリーム、出力ストリーム、およびエラー ストリームをリダイレクトできます。
このコンテキスト (UseShellExecute
) の "シェル" という単語は、コマンド シェル (たとえば、または) ではなくグラフィカル シェル (Windows シェルに似ています) を指し、 bash
sh
ユーザーがグラフィカル アプリケーションを起動したり、ドキュメントを開いたりできるようにします。
注意
UseShellExecutefalse
プロパティがUserName空の文字列でないnull
場合、またはInvalidOperationExceptionメソッドが呼び出されたときにProcess.Start(ProcessStartInfo)スローされる場合は必ず指定してください。
オペレーティング システム シェルを使用してプロセスを開始する場合は、任意のドキュメント (既定のオープン アクションを持つ実行可能ファイルに関連付けられている任意の登録済みファイルの種類) を起動し、オブジェクトを使用してファイルに対する操作 (印刷など) を Process 実行できます。 この場合 UseShellExecute 、 false
オブジェクトを使用 Process して実行可能ファイルのみを開始できます。
注意
UseShellExecute プロパティを true
に設定する場合は、次の値を ErrorDialog 指定する true
必要があります。
を設定する場合はWindowStyle、 UseShellExecute にProcessWindowStyle.Hidden設定するtrue
必要があります。
WorkingDirectory
プロパティの動作は WorkingDirectory 、プロパティの UseShellExecute 値によって異なります。 When UseShellExecute is true
, the WorkingDirectory property specifies the location of the executable. 空の文字列の場合 WorkingDirectory は、現在のディレクトリに実行可能ファイルが含まれていると見なされます。
このプロパティ UseShellExecute は false
、 WorkingDirectory 実行可能ファイルの検索に使用されません。 代わりに、開始され、新しいプロセスのコンテキスト内でのみ意味を持つプロセスによってのみ使用されます。 この UseShellExecute プロパティには false
、 FileName 実行可能ファイルへの完全修飾パス、または PATH 環境変数で指定されたフォルダー内でシステムが検索を試みる単純な実行可能ファイル名を指定できます。