ProcessStartInfo.UseShellExecute プロパティ

定義

プロセスの起動にオペレーティング システムのシェルを使用するかどうかを示す値を取得または設定します。

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 シェルに似ています) を指し、shbashユーザーがグラフィカル アプリケーションを起動したり、ドキュメントを開いたりできるようにします。

注意

UseShellExecutefalseプロパティが または空のUserName文字列でないnull場合は である必要があります。またはInvalidOperationException、 メソッドが呼び出されたときに がProcess.Start(ProcessStartInfo)スローされます。

オペレーティング システム シェルを使用してプロセスを開始する場合は、任意のドキュメント (既定のオープン アクションを持つ実行可能ファイルに関連付けられている任意の登録済みファイルの種類) を起動し、 オブジェクトを使用してファイルに対する操作 (印刷など) を Process 実行できます。 が のfalse場合UseShellExecute、 オブジェクトを使用Processして実行可能ファイルのみを開始できます。

注意

UseShellExecuteプロパティを に設定する場合はtrue、 であるErrorDialogtrue必要があります。

WorkingDirectory

プロパティの動作は WorkingDirectory 、プロパティの UseShellExecute 値によって異なります。 が のtrue場合UseShellExecute、 プロパティはWorkingDirectory実行可能ファイルの場所を指定します。 が空の文字列の場合 WorkingDirectory は、現在のディレクトリに実行可能ファイルが含まれていると見なされます。

が のfalse場合UseShellExecuteWorkingDirectory プロパティは実行可能ファイルの検索に使用されません。 代わりに、開始され、新しいプロセスのコンテキスト内でのみ意味を持つプロセスによってのみ使用されます。 が のfalse場合UseShellExecuteFileName プロパティには、実行可能ファイルへの完全修飾パス、または環境変数でPATH指定されたフォルダー内でシステムが検索を試みる単純な実行可能ファイル名のいずれかを指定できます。 検索パスの解釈は、オペレーティング システムによって異なります。 詳細については、コマンド プロンプトで または man sh と入力HELP PATHします。

適用対象

こちらもご覧ください