Process クラスとは? わかりやすく解説

Process クラス

ローカル プロセスリモート プロセスアクセスできるようにして、ローカル システム プロセス起動中断ができるようにします。

名前空間: System.Diagnostics
アセンブリ: 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();
}

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
      System.Diagnostics.Process
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Process メンバ
System.Diagnostics 名前空間
Start
ProcessStartInfo
CloseMainWindow
Kill
ProcessThread


このページでは「.NET Framework クラス ライブラリ リファレンス」からProcess クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からProcess クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からProcess クラス を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Process クラス」の関連用語

Process クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Process クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS