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 します。 既定値は false (または、.NET Framework アプリでは true) です。
例外
ユニバーサル Windows プラットフォーム (UWP) アプリで値を true に設定しようとすると発生します。
例
// 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
注釈
ProcessStartInfo クラスは、プロセスの開始時に使用される値のセットを指定します。
UseShellExecute プロパティを false に設定すると、入力、出力、およびエラー ストリームをリダイレクトできます。
このコンテキスト (UseShellExecute) の "shell" という単語は、コマンド シェル ( bash や shなど) ではなくグラフィカル シェル (Windows シェルと同様) を指し、ユーザーがグラフィカル アプリケーションを起動したり、ドキュメントを開いたりできるようにします。
Note
UseShellExecuteプロパティがfalseまたは空の文字列でない場合、UserNameはnullする必要があります。そうでないと、InvalidOperationExceptionメソッドが呼び出されたときにProcess.Start(ProcessStartInfo)がスローされます。
オペレーティング システム シェルを使用してプロセスを開始する場合は、任意のドキュメント (既定のオープン アクションを持つ実行可能ファイルに関連付けられている任意の登録済みファイルの種類) を起動し、 Process オブジェクトを使用して、ファイルに対する操作 (印刷など) を実行できます。
UseShellExecuteがfalseされている場合は、Process オブジェクトを使用して実行可能ファイルのみを開始できます。
Note
UseShellExecute プロパティを true に設定する場合、ErrorDialogはtrueする必要があります。
ワーキングディレクトリ (WorkingDirectory)
WorkingDirectory プロパティの動作は、UseShellExecute プロパティの値によって異なります。
UseShellExecuteがtrueされている場合、WorkingDirectory プロパティは実行可能ファイルの場所を指定します。
WorkingDirectoryが空の文字列の場合は、現在のディレクトリに実行可能ファイルが含まれていると見なされます。
UseShellExecuteがfalseされている場合、WorkingDirectory プロパティは実行可能ファイルの検索に使用されません。 それは、開始されたプロセスによってのみ使用され、新しいプロセスのコンテキスト内でのみ意味を持ちます。
UseShellExecuteがfalseされている場合、FileName プロパティには、実行可能ファイルへの完全修飾パス、またはPATH環境変数で指定されたフォルダー内でシステムが検索を試みる単純な実行可能ファイル名を指定できます。 検索パスの解釈は、オペレーティング システムによって異なります。 詳細については、コマンド プロンプトで「 HELP PATH または man sh 」と入力します。