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 プロパティ
Weblioに収録されているすべての辞書からProcess.StartInfo プロパティを検索する場合は、下記のリンクをクリックしてください。

- Process.StartInfo プロパティのページへのリンク