Process.StartInfo プロパティ
アセンブリ: System (system.dll 内)

Dim instance As Process Dim value As ProcessStartInfo value = instance.StartInfo instance.StartInfo = value
public: property ProcessStartInfo^ StartInfo { ProcessStartInfo^ get (); void set (ProcessStartInfo^ value); }
/** @property */ public ProcessStartInfo get_StartInfo () /** @property */ public void set_StartInfo (ProcessStartInfo value)
public function get StartInfo () : ProcessStartInfo public function set StartInfo (value : ProcessStartInfo)
プロセスを起動するときに使用するデータを表す ProcessStartInfo。これらの引数には、プロセスの起動時に使用する実行可能ファイルまたは文書の名前があります。


StartInfo は、プロセスを起動するために使用するパラメータのセットを表します。Start を呼び出すときは、StartInfo を使用して、起動するプロセスを指定します。設定する必要がある唯一の StartInfo メンバは、FileName プロパティです。FileName プロパティの指定によるプロセスの起動は、Windows の [スタート] メニューの [ファイル名を指定して実行] ダイアログ ボックスへの情報の入力と同様です。そのため、FileName プロパティで実行可能ファイルを表す必要はありません。システムにインストールされているアプリケーションに関連付けられている拡張子を持つ任意のファイルの種類を指定できます。たとえば、テキスト ファイルをメモ帳などのエディタに関連付けている場合は、FileName に拡張子 .txt の付いたファイルを使用できます。.doc ファイルを Microsoft Word などのワード プロセッシング ツールに関連付けている場合は、.doc を使用できます。同様に、[ファイル名を指定して実行] ダイアログ ボックスで実行可能ファイル名は拡張子 .exe が付いているかどうかに関係なく受け入れられるのと同じように、FileName メンバでも拡張子 .exe は省略できます。たとえば、FileName プロパティには "Notepad.exe" または "Notepad" を設定できます。
ファイル名が .doc ファイルなど実行可能ファイル以外のファイルの場合は、ファイルに対して実行するアクションを指定する動詞を含めることができます。たとえば、拡張子 .doc で終わるファイルの場合、Verb に "Print" を設定できます。Verb プロパティの値を手動で入力する場合、FileName プロパティで指定するファイル名に拡張子を付ける必要はありません。ただし、使用できる動詞を判断するのに Verbs プロパティを使用する場合は、ファイル拡張子を付ける必要があります。
Start メソッドがプロセスで呼び出される前であれば、StartInfo プロパティで指定したパラメータを変更できます。プロセス開始後は、StartInfo 値を変更しても、関連付けられたプロセスの開始やプロセスへの反映は行われません。ProcessStartInfo.UserName プロパティと ProcessStartInfo.Password プロパティを設定してStart(ProcessStartInfo) を呼び出した場合、アンマネージ関数 CreateProcessWithLogonW が呼び出されます。これにより、CreateNoWindow プロパティの値が true の場合や、WindowStyle プロパティの値が Hidden の場合でも、新しいウィンドウでプロセスが開始されます。
プロセスの開始に Start メソッドを使用しなかった場合、StartInfo プロパティはプロセス開始に使用されたパラメータを反映しません。たとえば、GetProcesses を使用してコンピュータで実行中のプロセスの配列を取得する場合、各 Process の StartInfo プロパティには、プロセス開始に使用された元のファイル名や引数は含まれません。
プロセスを起動するとき、このファイル名が (読み取り専用) MainModule プロパティに設定されるファイルになります。プロセスを起動した後でプロセスに関連付けられた実行可能ファイルを取得するには、MainModule プロパティを使用します。関連付けられたプロセスがまだ起動されていない Process インスタンスの実行可能ファイルを設定するには、StartInfo プロパティの FileName メンバを使用します。StartInfo プロパティのメンバは、プロセスの Start メソッドに渡される引数であるため、関連付けられたプロセスが起動された後で FileName プロパティを変更しても、MainModule プロパティはリセットされません。これらのプロパティは、関連付けられたプロセスの初期化にだけ使用します。

実行するファイル、それに対して実行するアクション、およびユーザー インターフェイスを表示するかどうかを指定する値を StartInfo に格納する例を次に示します。
Imports System Imports System.Diagnostics Imports System.ComponentModel Namespace MyProcessSample _ '/ <summary> '/ Shell for the sample. '/ </summary> Class MyProcess ' These are the Win32 error code for file not found or access denied. Private ERROR_FILE_NOT_FOUND As Integer = 2 Private ERROR_ACCESS_DENIED As Integer = 5 '/ <summary> '/ Prints a file with a .doc extension. '/ </summary> Sub PrintDoc() Dim myProcess As New Process() Try ' Get the path that stores user documents. Dim myDocumentsPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal) myProcess.StartInfo.FileName = myDocumentsPath + "\MyFile.doc" myProcess.StartInfo.Verb = "Print" myProcess.StartInfo.CreateNoWindow = True myProcess.Start() Catch e As Win32Exception If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then Console.WriteLine((e.Message + ". Check the path.")) Else If e.NativeErrorCode = ERROR_ACCESS_DENIED Then ' Note that if your word processor might generate exceptions ' such as this, which are handled first. Console.WriteLine((e.Message + ". You do not have permission to print this file.")) End If End If End Try End Sub 'PrintDoc Public Shared Sub Main() Dim myProcess As New MyProcess() myProcess.PrintDoc() End Sub 'Main End Class 'MyProcess End Namespace 'MyProcessSample
using System; using System.Diagnostics; using System.ComponentModel; namespace MyProcessSample { /// <summary> /// Shell for the sample. /// </summary> class MyProcess { // These are the Win32 error code for file not found or access denied. const int ERROR_FILE_NOT_FOUND =2; const int ERROR_ACCESS_DENIED = 5; /// <summary> /// Prints a file with a .doc extension. /// </summary> void PrintDoc() { Process myProcess = new Process(); try { // Get the path that stores user documents. string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); myProcess.StartInfo.FileName = myDocumentsPath + "\\MyFile.doc"; myProcess.StartInfo.Verb = "Print"; myProcess.StartInfo.CreateNoWindow = true; myProcess.Start(); } catch (Win32Exception e) { if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND) { Console.WriteLine(e.Message + ". Check the path."); } else if (e.NativeErrorCode == ERROR_ACCESS_DENIED) { // Note that if your word processor might generate exceptions // such as this, which are handled first. Console.WriteLine(e.Message + ". You do not have permission to print this file."); } } } public static void Main() { MyProcess myProcess = new MyProcess(); myProcess.PrintDoc(); } } }
#using <System.dll> using namespace System; using namespace System::Diagnostics; using namespace System::ComponentModel; // These are the Win32 error code for file not found or access denied. #define ERROR_FILE_NOT_FOUND 2 #define ERROR_ACCESS_DENIED 5 int main() { Process^ myProcess = gcnew Process; try { // Get the path that stores user documents. String^ myDocumentsPath = Environment::GetFolderPath( Environment::SpecialFolder::Personal ); myProcess->StartInfo->FileName = String::Concat( myDocumentsPath, "\\MyFile.doc" ); myProcess->StartInfo->Verb = "Print"; myProcess->StartInfo->CreateNoWindow = true; myProcess->Start(); } catch ( Win32Exception^ e ) { if ( e->NativeErrorCode == ERROR_FILE_NOT_FOUND ) { Console::WriteLine( "{0}. Check the path.", e->Message ); } else if ( e->NativeErrorCode == ERROR_ACCESS_DENIED ) { // Note that if your word processor might generate exceptions // such as this, which are handled first. Console::WriteLine( "{0}. You do not have permission to print this file.", e->Message ); } } }


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ProcessStartInfo クラス
アセンブリ: System (system.dll 内)


![]() |
---|
このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、SharedState または SelfAffectingProcessMgmt です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。 |
ProcessStartInfo は、Process コンポーネントと組み合わせて使用します。Process クラスを使用してプロセスを起動すると、実行中のプロセスに接続するときに利用できる情報だけでなく、プロセス情報にもアクセスできます。
ProcessStartInfo クラスを使用して、起動するプロセスをさらに制御できます。少なくとも、手動またはコンストラクタを使用して、FileName プロパティを設定する必要があります。ファイル名は、任意のアプリケーションまたはドキュメントにします。ここでいうドキュメントとは、"open" という既定のアクションが関連付けられている任意のファイル タイプです。登録されているファイル タイプと、コンピュータ上でこれらに関連付けられているアプリケーションは、オペレーティング システムを通じて利用できる [フォルダ オプション] ダイアログ ボックスで参照できます。[詳細設定] ボタンを使用すると、登録されている特定のファイル タイプに "open" アクションが関連付けられているかどうかを示すダイアログ ボックスが表示されます。
さらにその他のプロパティを設定して、そのファイルに対して実行するアクションを定義できます。FileName プロパティの種類に固有の値を Verb プロパティに指定できます。たとえば、ドキュメントの種類に対して "印刷" を指定できます。さらに、ファイルのオープン プロシージャに渡すコマンド ライン引数になるように、Arguments プロパティ値を指定できます。たとえば、FileName プロパティにテキスト エディタ アプリケーションを指定すると、Arguments プロパティを使用してエディタで開くテキスト ファイルを指定できます。
標準入力は通常、キーボードで、標準出力と標準エラー出力は通常、モニタ画面です。ただし、RedirectStandardInput、RedirectStandardOutput、RedirectStandardError の各プロパティを使用すると、プロセスが入力を取得したり出力を返す先をファイルまたはその他のデバイスにできます。Process コンポーネントの StandardInput、StandardOutput、または StandardError の各プロパティを使用する場合は、まず対応する値を ProcessStartInfo プロパティに設定する必要があります。設定しないと、ストリームの読み取りまたは書き込みを実行したときに、例外がスローされます。
UseShellExecute を設定し、オペレーティング システムのシェルを使用してプロセスを起動するかどうかを指定します。
ProcessStartInfo プロパティの値を変更できるのは、プロセスを起動するまでです。プロセスを開始した後で、これらの値を変更しても影響はありません。

Imports System Imports System.Diagnostics Imports System.ComponentModel Namespace MyProcessSample _ '/ <summary> '/ Shell for the sample. '/ </summary> Class MyProcess '/ <summary> '/ Opens the Internet Explorer application. '/ </summary> Public Sub OpenApplication(myFavoritesPath As String) ' Start Internet Explorer. Defaults to the home page. Process.Start("IExplore.exe") ' Display the contents of the favorites folder in the browser. Process.Start(myFavoritesPath) End Sub 'OpenApplication '/ <summary> '/ Opens urls and .html documents using Internet Explorer. '/ </summary> Sub OpenWithArguments() ' url's are not considered documents. They can only be opened ' by passing them as arguments. Process.Start("IExplore.exe", "www.northwindtraders.com") ' Start a Web page using a browser associated with .html and .asp files. Process.Start("IExplore.exe", "C:\myPath\myFile.htm") Process.Start("IExplore.exe", "C:\myPath\myFile.asp") End Sub 'OpenWithArguments '/ <summary> '/ Uses the ProcessStartInfo class to start new processes, both in a minimized '/ mode. '/ </summary> Sub OpenWithStartInfo() Dim startInfo As New ProcessStartInfo("IExplore.exe") startInfo.WindowStyle = ProcessWindowStyle.Minimized Process.Start(startInfo) startInfo.Arguments = "www.northwindtraders.com" Process.Start(startInfo) End Sub 'OpenWithStartInfo Shared Sub Main() ' Get the path that stores favorite links. Dim myFavoritesPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites) Dim myProcess As New MyProcess() myProcess.OpenApplication(myFavoritesPath) myProcess.OpenWithArguments() myProcess.OpenWithStartInfo() End Sub 'Main End Class 'MyProcess End Namespace 'MyProcessSample
using System; using System.Diagnostics; using System.ComponentModel; namespace MyProcessSample { /// <summary> /// Shell for the sample. /// </summary> class MyProcess { /// <summary> /// Opens the Internet Explorer application. /// </summary> void OpenApplication(string myFavoritesPath) { // Start Internet Explorer. Defaults to the home page. Process.Start("IExplore.exe"); // Display the contents of the favorites folder in the browser. Process.Start(myFavoritesPath); } /// <summary> /// Opens urls and .html documents using Internet Explorer. /// </summary> void OpenWithArguments() { // url's are not considered documents. They can only be opened // by passing them as arguments. Process.Start("IExplore.exe", "www.northwindtraders.com"); // Start a Web page using a browser associated with .html and .asp files. Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm"); Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp"); } /// <summary> /// Uses the ProcessStartInfo class to start new processes, both in a minimized /// mode. /// </summary> void OpenWithStartInfo() { ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe"); startInfo.WindowStyle = ProcessWindowStyle.Minimized; Process.Start(startInfo); startInfo.Arguments = "www.northwindtraders.com"; Process.Start(startInfo); } static void Main() { // Get the path that stores favorite links. string myFavoritesPath = Environment.GetFolderPath(Environment.SpecialFolder.Favorites); MyProcess myProcess = new MyProcess(); myProcess.OpenApplication(myFavoritesPath); myProcess.OpenWithArguments(); myProcess.OpenWithStartInfo(); } } }
#using <System.dll> using namespace System; using namespace System::Diagnostics; using namespace System::ComponentModel; /// <summary> /// Opens the Internet Explorer application. /// </summary> void OpenApplication( String^ myFavoritesPath ) { // Start Internet Explorer. Defaults to the home page. Process::Start( "IExplore.exe" ); // Display the contents of the favorites folder in the browser. Process::Start( myFavoritesPath ); } /// <summary> /// Opens urls and .html documents using Internet Explorer. /// </summary> void OpenWithArguments() { // url's are not considered documents. They can only be opened // by passing them as arguments. Process::Start( "IExplore.exe", "www.northwindtraders.com" ); // Start a Web page using a browser associated with .html and .asp files. Process::Start( "IExplore.exe", "C:\\myPath\\myFile.htm" ); Process::Start( "IExplore.exe", "C:\\myPath\\myFile.asp" ); } /// <summary> /// Uses the ProcessStartInfo class to start new processes, both in a minimized /// mode. /// </summary> void OpenWithStartInfo() { ProcessStartInfo^ startInfo = gcnew ProcessStartInfo( "IExplore.exe" ); startInfo->WindowStyle = ProcessWindowStyle::Minimized; Process::Start( startInfo ); startInfo->Arguments = "www.northwindtraders.com"; Process::Start( startInfo ); } int main() { // Get the path that stores favorite links. String^ myFavoritesPath = Environment::GetFolderPath( Environment::SpecialFolder::Favorites ); OpenApplication( myFavoritesPath ); OpenWithArguments(); OpenWithStartInfo(); }


System.Diagnostics.ProcessStartInfo


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ProcessStartInfo コンストラクタ ()
アセンブリ: System (system.dll 内)


プロセスを起動する前に、少なくとも FileName プロパティを設定する必要があります。ファイル名は、任意のアプリケーションまたはドキュメントにします。この場合、ドキュメントは、"open" という既定のアクションが関連付けられている任意のファイル タイプとして定義されます。登録されているファイル タイプと、コンピュータ上でこれらに関連付けられているアプリケーションは、オペレーティング システムを通じて利用できる [フォルダ オプション] ダイアログ ボックスで参照できます。[詳細設定] ボタンを使用すると、登録されている特定のファイル タイプに "open" アクションが関連付けられているかどうかを示すダイアログ ボックスが表示されます。
プロセスを起動する前に、その他のプロパティを設定することもできます。Verb プロパティで、"印刷" など、FileName プロパティが示すファイルに対して実行するアクションを指定します。Arguments プロパティで、システムがファイルを開くときにファイルに渡すコマンド ライン引数を渡すことができます。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ProcessStartInfo コンストラクタ (String)
アセンブリ: System (system.dll 内)


ファイル名は、任意のアプリケーションまたはドキュメントにします。この場合、ドキュメントは、"open" という既定のアクションが関連付けられている任意のファイル タイプとして定義されます。登録されているファイル タイプと、コンピュータ上でこれらに関連付けられているアプリケーションは、オペレーティング システムを通じて利用できる [フォルダ オプション] ダイアログ ボックスで参照できます。[詳細設定] ボタンを使用すると、登録されている特定のファイル タイプに "open" アクションが関連付けられているかどうかを示すダイアログ ボックスが表示されます。
このコンストラクタを呼び出した後、FileName プロパティを変更できるのは、プロセスを起動するまでです。プロセスを開始した後で、これらの値を変更しても影響はありません。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ProcessStartInfo コンストラクタ (String, String)
アセンブリ: System (system.dll 内)

Dim fileName As String Dim arguments As String Dim instance As New ProcessStartInfo(fileName, arguments)

ファイル名は、任意のアプリケーションまたはドキュメントにします。この場合、ドキュメントは、"open" という既定のアクションが関連付けられている任意のファイル タイプとして定義されます。登録されているファイル タイプと、コンピュータ上でこれらに関連付けられているアプリケーションは、オペレーティング システムを通じて利用できる [フォルダ オプション] ダイアログ ボックスで参照できます。[詳細設定] ボタンを使用すると、登録されている特定のファイル タイプに "open" アクションが関連付けられているかどうかを示すダイアログ ボックスが表示されます。
このコンストラクタを呼び出した後、FileName プロパティまたは Arguments プロパティを変更できるのは、プロセスを起動するまでです。プロセスを開始した後で、これらの値を変更しても影響はありません。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ProcessStartInfo コンストラクタ

名前 | 説明 |
---|---|
ProcessStartInfo () | プロセスを起動するときに使用するファイル名を指定せずに、ProcessStartInfo クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
ProcessStartInfo (String) | ProcessStartInfo クラスの新しいインスタンスを初期化し、アプリケーションやドキュメントなど、プロセスを起動するときに使用するファイル名を指定します。 |
ProcessStartInfo (String, String) | ProcessStartInfo クラスの新しいインスタンスを初期化し、プロセスを起動するときに使用するアプリケーション ファイル名と、アプリケーションに渡すコマンド ライン引数のセットを指定します。 .NET Compact Framework によってサポートされています。 |

ProcessStartInfo プロパティ
ProcessStartInfo メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

ProcessStartInfo メンバ
ProcessStartInfo データ型で公開されるメンバを以下の表に示します。



名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- Process.StartInfoのページへのリンク