Process イベント

名前 | 説明 | |
---|---|---|
![]() | Disposed | コンポーネントの Disposed イベントを待機するイベント ハンドラを追加します。 ( Component から継承されます。) |
![]() | OutputDataReceived | アプリケーションがリダイレクトされた StandardOutput ストリームに書き込む場合に発生します。 |

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


![]() |
---|
このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、Synchronization、SharedState、ExternalProcessMgmt、または SelfAffectingProcessMgmt です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。 |
Process コンポーネントは、コンピュータで実行中のプロセスにアクセスできるようにします。プロセスとは、簡単に言うと、実行中のアプリケーションです。スレッドは、オペレーティング システムでプロセッサ時間を割り当てるための基本単位です。スレッドは、プロセスのコードの任意の部分を実行できます。別のスレッドで現在実行中の部分も実行できます。
Process コンポーネントは、アプリケーションの起動、中断、制御、監視に役立つツールです。Process コンポーネントを使用して、実行中のプロセスの一覧を取得したり、新しいプロセスを起動したりできます。Process コンポーネントは、システム プロセスへのアクセスに使用します。Process コンポーネントを初期化した後は、実行中のプロセスに関する情報を取得するために使用できます。これらの情報には、スレッドのセット、読み込まれたモジュール (.dll ファイルと実行可能ファイル (.EXE))、およびプロセスが使用しているメモリ容量などのパフォーマンス情報があります。
システムでパス変数を引用符で囲んで宣言している場合は、その場所で見つかったプロセスを開始するときに、そのパスの絶対パスを指定する必要があります。これを実行しないと、システムはパスを見つけることができません。たとえば、c:\mypath が自分のパスに含まれておらず、path = %path%;"c:\mypath" のように二重引用符を使用してこれを追加した場合、c:\mypath 内のプロセスを起動するときには、必ずそのプロセスを完全に限定する必要があります。
プロセス コンポーネントは、プロパティのグループに関するすべての情報を一度に取得します。Process コンポーネントが任意のグループのあるメンバに関する情報を取得すると、そのグループの他のプロパティの値がキャッシュされます。Refresh メソッドを呼び出すまで、そのグループの他のメンバに関する新しい情報は取得されません。そのため、プロパティ値が、Refresh メソッドを最後に呼び出したときよりも新しいという保証はありません。グループの内訳は、オペレーティング システムに依存します。
システム プロセスは、プロセス ID によってシステム上で一意に識別されます。多くの Windows リソースと同じように、プロセスもハンドルで識別されます。しかし、ハンドルはコンピュータで一意でない可能性があります。ハンドルとは、リソース識別子を一般的に表現した用語です。オペレーティング システムは、プロセス ハンドルを維持します。プロセスが終了していても、Process コンポーネントの Handle プロパティを通じて、プロセス ハンドルにアクセスできます。そのため、ExitCode (正常終了した場合はゼロ、それ以外の場合は 0 以外のエラー コード) や ExitTime など、プロセスの管理情報を取得できます。ハンドルは貴重なリソースであるため、ハンドルのリークはメモリのリークよりも有害です。

Process クラスのインスタンスを作成してプロセスを起動する例を次に示します。
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 ); } } }
Process クラス自体と静的な Start メソッドを使用してプロセスを起動する例を次に示します。
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.MarshalByRefObject
System.ComponentModel.Component
System.Diagnostics.Process


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


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


MachineName プロパティを指定しない場合は、既定値はローカル コンピュータ (".") です。
新しい Process コンポーネントをコンピュータ上のプロセスに関連付けるには、2 つの方法があります。1 つは、コンストラクタを使用して Process コンポーネントを作成し、StartInfo プロパティの適切なメンバを設定し、Start を呼び出して Process を新しいシステム プロセスに関連付ける方法です。もう 1 つは、GetProcessById または GetProcesses の戻り値の 1 つを使用して Process を実行中のシステム プロセスに関連付ける方法です。
Start メソッドの static オーバーロードを使用して新しいシステム プロセスを起動する場合、メソッドは新しい Process コンポーネントを作成し、プロセスに関連付けます。
ProcessStartInfo.UseShellExecute プロパティが既定値の true に設定されている場合は、Windows [スタート] メニューの [ファイル名を指定して実行] ダイアログ ボックスを使用する場合と似た方法で、アプリケーションおよびドキュメントを起動できます。ProcessStartInfo.UseShellExecute が false の場合は、実行可能ファイルだけを実行できます。
コマンド ラインから呼び出すことができる実行可能ファイルは、2 つの方法のいずれかで起動できます。1 つは、StartInfo プロパティの適切なメンバを設定し、Start メソッドをパラメータなしで呼び出す方法です。もう 1 つは、適切なパラメータを staticStart メンバに渡す方法です。
Process コンポーネントは、コンストラクタ、いずれかの静的 Start オーバーロード、または GetProcessById、GetProcesses、GetProcessesByName の各メソッドのいずれかを使用して作成できます。作成すると、関連付けられたプロセスを参照できるようになります。これは、プロセス プロパティがメモリ上で変更されたときに自動的に更新される動的なビューではありません。コンポーネントの Refresh を呼び出して、Process プロパティ情報をアプリケーションで更新する必要があります。


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


Process プロパティ

名前 | 説明 | |
---|---|---|
![]() | BasePriority | 関連付けられたプロセスの基本優先順位を取得します。 |
![]() | Container | Component を格納している IContainer を取得します。 ( Component から継承されます。) |
![]() | Site | Component の ISite を取得または設定します。 ( Component から継承されます。) |
![]() | StandardError | アプリケーションのエラー出力の読み取りに使用されるストリームを取得します。 |
![]() | StandardInput | アプリケーションの入力の書き込みに使用されるストリームを取得します。 |
![]() | StandardOutput | アプリケーションの出力の読み取りに使用されるストリームを取得します。 |
![]() ![]() | StartTime | 関連付けられたプロセスが起動された時刻を取得します。 |
![]() | SynchronizingObject | プロセス終了イベントの結果として発行されるイベント ハンドラ呼び出しをマーシャリングするために使用するオブジェクトを取得または設定します。 |
![]() | Threads | 関連付けられたプロセスで実行されているスレッドのセットを取得します。 |
![]() | TotalProcessorTime | このプロセスの合計プロセッサ時間を取得します。 |
![]() | UserProcessorTime | このプロセスのユーザー プロセッサ時間を取得します。 |
![]() | VirtualMemorySize | プロセスの仮想メモリのサイズを取得します。 |
![]() | VirtualMemorySize64 | 関連付けられたプロセスに割り当てられた仮想メモリの量を取得します。 |
![]() | WorkingSet | 関連付けられたプロセスの物理メモリ使用量を取得します。 |
![]() | WorkingSet64 | 関連付けられたプロセスに割り当てられた物理メモリの量を取得します。 |

名前 | 説明 | |
---|---|---|
![]() | CanRaiseEvents | コンポーネントがイベントを発生させることがきるかどうかを示す値を取得します。 ( Component から継承されます。) |
![]() | DesignMode | Component が現在デザイン モードかどうかを示す値を取得します。 ( Component から継承されます。) |
![]() | Events | Component に結び付けられているイベント ハンドラのリストを取得します。 ( Component から継承されます。) |

Process メソッド


名前 | 説明 | |
---|---|---|
![]() | Dispose | オーバーロードされます。 オーバーライドされます。 |
![]() | Finalize | Component がガベージ コレクションによってクリアされる前に、アンマネージ リソースを解放し、その他のクリーンアップ操作を実行します。 ( Component から継承されます。) |
![]() | GetService | Component またはその Container で提供されるサービスを表すオブジェクトを返します。 ( Component から継承されます。) |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |
![]() | OnExited | Exited イベントを発生させます。 |

Process メンバ
ローカル プロセスとリモート プロセスにアクセスできるようにして、ローカル システム プロセスの起動と中断ができるようにします。
Process データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | BasePriority | 関連付けられたプロセスの基本優先順位を取得します。 |
![]() | Container | Component を格納している IContainer を取得します。(Component から継承されます。) |
![]() | Site | Component の ISite を取得または設定します。(Component から継承されます。) |
![]() | StandardError | アプリケーションのエラー出力の読み取りに使用されるストリームを取得します。 |
![]() | StandardInput | アプリケーションの入力の書き込みに使用されるストリームを取得します。 |
![]() | StandardOutput | アプリケーションの出力の読み取りに使用されるストリームを取得します。 |
![]() ![]() | StartTime | 関連付けられたプロセスが起動された時刻を取得します。 |
![]() | SynchronizingObject | プロセス終了イベントの結果として発行されるイベント ハンドラ呼び出しをマーシャリングするために使用するオブジェクトを取得または設定します。 |
![]() | Threads | 関連付けられたプロセスで実行されているスレッドのセットを取得します。 |
![]() | TotalProcessorTime | このプロセスの合計プロセッサ時間を取得します。 |
![]() | UserProcessorTime | このプロセスのユーザー プロセッサ時間を取得します。 |
![]() | VirtualMemorySize | プロセスの仮想メモリのサイズを取得します。 |
![]() | VirtualMemorySize64 | 関連付けられたプロセスに割り当てられた仮想メモリの量を取得します。 |
![]() | WorkingSet | 関連付けられたプロセスの物理メモリ使用量を取得します。 |
![]() | WorkingSet64 | 関連付けられたプロセスに割り当てられた物理メモリの量を取得します。 |

名前 | 説明 | |
---|---|---|
![]() | CanRaiseEvents | コンポーネントがイベントを発生させることがきるかどうかを示す値を取得します。(Component から継承されます。) |
![]() | DesignMode | Component が現在デザイン モードかどうかを示す値を取得します。(Component から継承されます。) |
![]() | Events | Component に結び付けられているイベント ハンドラのリストを取得します。(Component から継承されます。) |


名前 | 説明 | |
---|---|---|
![]() | Dispose | オーバーロードされます。 オーバーライドされます。 |
![]() | Finalize | Component がガベージ コレクションによってクリアされる前に、アンマネージ リソースを解放し、その他のクリーンアップ操作を実行します。 (Component から継承されます。) |
![]() | GetService | Component またはその Container で提供されるサービスを表すオブジェクトを返します。 (Component から継承されます。) |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |
![]() | OnExited | Exited イベントを発生させます。 |

名前 | 説明 | |
---|---|---|
![]() | Disposed | コンポーネントの Disposed イベントを待機するイベント ハンドラを追加します。(Component から継承されます。) |
![]() | OutputDataReceived | アプリケーションがリダイレクトされた StandardOutput ストリームに書き込む場合に発生します。 |

固有名詞の分類
Weblioに収録されているすべての辞書からProcessを検索する場合は、下記のリンクをクリックしてください。

- Processのページへのリンク