次の方法で共有


ProcessStartInfo.UseShellExecute プロパティ

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

名前空間: System.Diagnostics
アセンブリ: System (system.dll 内)

構文

'宣言
Public Property UseShellExecute As Boolean
'使用
Dim instance As ProcessStartInfo
Dim value As Boolean

value = instance.UseShellExecute

instance.UseShellExecute = value
public bool UseShellExecute { get; set; }
public:
property bool UseShellExecute {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_UseShellExecute ()

/** @property */
public void set_UseShellExecute (boolean value)
public function get UseShellExecute () : boolean

public function set UseShellExecute (value : boolean)

プロパティ値

プロセスを起動するときにシェルを使用する場合は true。それ以外の場合、プロセスは実行可能ファイルから直接作成されます。既定値は true です。

解説

このプロパティを false に設定すると、入力、出力、エラーの各ストリームをリダイレクトできます。

注意

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

オペレーティング システムのシェルを使用してプロセスを起動すると、Process コンポーネントを使用して、任意のドキュメント (任意の登録済みファイル タイプ。既定の "open" アクションが実行できるように関連付けられています。) を起動し、印刷などのファイルに対する操作を実行できます。UseShellExecutefalse の場合は、Process コンポーネントを使用して、実行可能ファイルの起動だけ実行できます。

注意

ErrorDialog プロパティを true に設定するには、UseShellExecutetrue にする必要があります。

WorkingDirectory プロパティの動作は、UseShellExecutetrue の場合と UseShellExecutefalse の場合とで異なります。UseShellExecutetrue の場合は、WorkingDirectory プロパティは実行可能ファイルの場所を指定します。WorkingDirectory が空の文字列の場合は、現在のディレクトリに実行可能ファイルが格納されていると解釈されます。

UseShellExecutefalse の場合は、実行可能ファイルの検索に WorkingDirectory プロパティは使用されません。代わりに、このプロパティは起動されるプロセスにより使用され、新しいプロセスのコンテキスト内でだけ意味を持ちます。

使用例

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()
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();
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();

プラットフォーム

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 2.0

参照

関連項目

ProcessStartInfo クラス
ProcessStartInfo メンバ
System.Diagnostics 名前空間
ProcessStartInfo.RedirectStandardInput プロパティ
ProcessStartInfo.RedirectStandardOutput プロパティ
ProcessStartInfo.RedirectStandardError プロパティ