Process.GetProcessesByName メソッド

定義

新しい Process コンポーネントの配列を作成し、指定したプロセス名を共有する既存のプロセス リソースに関連付けます。

オーバーロード

GetProcessesByName(String, String)

新しい Process コンポーネントの配列を作成し、指定したプロセス名を共有するリモート コンピューター上のすべてのプロセス リソースに関連付けます。

GetProcessesByName(String)

新しい Process コンポーネントの配列を作成し、指定したプロセス名を共有するローカル コンピューター上のすべてのプロセス リソースに関連付けます。

GetProcessesByName(String, String)

ソース:
Process.Linux.cs
ソース:
Process.Linux.cs
ソース:
Process.Linux.cs

新しい Process コンポーネントの配列を作成し、指定したプロセス名を共有するリモート コンピューター上のすべてのプロセス リソースに関連付けます。

public:
 static cli::array <System::Diagnostics::Process ^> ^ GetProcessesByName(System::String ^ processName, System::String ^ machineName);
public static System.Diagnostics.Process[] GetProcessesByName (string? processName, string machineName);
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.Process[] GetProcessesByName (string? processName, string machineName);
public static System.Diagnostics.Process[] GetProcessesByName (string processName, string machineName);
static member GetProcessesByName : string * string -> System.Diagnostics.Process[]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member GetProcessesByName : string * string -> System.Diagnostics.Process[]
Public Shared Function GetProcessesByName (processName As String, machineName As String) As Process()

パラメーター

processName
String

プロセスのフレンドリ名。

machineName
String

ネットワーク上のコンピューターの名前。

戻り値

指定したアプリケーションまたはファイルを実行しているプロセス リソースを表す Process 型の配列。

属性

例外

machineName パラメーターの構文が正しくありません。 長さがゼロ (0) の可能性があります。

machineName パラメーターが null です。

リモート コンピューターに対してこの操作を実行することは、オペレーティング システム プラットフォームでサポートされていません。

machineName に接続する試みが失敗しました。

または

プロセス情報を取得するために使用するパフォーマンス カウンター API へのアクセスに問題があります。 この例外は、Windows NT、Windows 2000、および Windows XP に固有のものです。

基になるシステム API にアクセスしようとして、問題が発生しました。

次の例では、現在のプロセス、ローカル コンピューターで実行されているプロセス、ローカル コンピューターで実行されているすべてのメモ帳のインスタンス、およびローカル コンピューター上の特定のプロセスの情報を取得します。 その後、リモート コンピューター上の同じプロセスの情報を取得します。

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;
int main()
{   
   // Get the current process.    
   Process^ currentProcess = Process::GetCurrentProcess();

   // Get all processes running on the local computer.
   array<Process^>^localAll = Process::GetProcesses();

   // Get all instances of Notepad running on the local computer.
   // This will return an empty array if notepad isn't running.
   array<Process^>^localByName = Process::GetProcessesByName("notepad");

   // Get a process on the local computer, using the process id.
   // This will throw an exception if there is no such process.
   Process^ localById = Process::GetProcessById(1234);


   // Get processes running on a remote computer. Note that this
   // and all the following calls will timeout and throw an exception
   // if "myComputer" and 169.0.0.0 do not exist on your local network.

   // Get all processes on a remote computer.
   array<Process^>^remoteAll = Process::GetProcesses("myComputer");

   // Get all instances of Notepad running on the specific computer, using machine name.
   array<Process^>^remoteByName = Process::GetProcessesByName( "notepad", "myComputer" );
   
   // Get all instances of Notepad running on the specific computer, using IP address.
   array<Process^>^ipByName = Process::GetProcessesByName( "notepad", "169.0.0.0" );
   
   // Get a process on a remote computer, using the process id and machine name.
   Process^ remoteById = Process::GetProcessById( 2345, "myComputer" );
}
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        void BindToRunningProcesses()
        {
            // Get the current process.
            Process currentProcess = Process.GetCurrentProcess();

            // Get all processes running on the local computer.
            Process[] localAll = Process.GetProcesses();

            // Get all instances of Notepad running on the local computer.
            // This will return an empty array if notepad isn't running.
            Process[] localByName = Process.GetProcessesByName("notepad");

            // Get a process on the local computer, using the process id.
            // This will throw an exception if there is no such process.
            Process localById = Process.GetProcessById(1234);

            // Get processes running on a remote computer. Note that this
            // and all the following calls will timeout and throw an exception
            // if "myComputer" and 169.0.0.0 do not exist on your local network.

            // Get all processes on a remote computer.
            Process[] remoteAll = Process.GetProcesses("myComputer");

            // Get all instances of Notepad running on the specific computer, using machine name.
            Process[] remoteByName = Process.GetProcessesByName("notepad", "myComputer");

            // Get all instances of Notepad running on the specific computer, using IP address.
            Process[] ipByName = Process.GetProcessesByName("notepad", "169.0.0.0");

            // Get a process on a remote computer, using the process id and machine name.
            Process remoteById = Process.GetProcessById(2345, "myComputer");
        }

        static void Main()
        {
            MyProcess myProcess = new MyProcess();
            myProcess.BindToRunningProcesses();
        }
    }
}
Imports System.Diagnostics
Imports System.ComponentModel

Namespace MyProcessSample
    Class MyProcess
        Sub BindToRunningProcesses()
            ' Get the current process. You can use currentProcess from this point
            ' to access various properties and call methods to control the process.
            Dim currentProcess As Process = Process.GetCurrentProcess()

            ' Get all processes running on the local computer.
            Dim localAll As Process() = Process.GetProcesses()

            ' Get all instances of Notepad running on the local computer.
            ' This will return an empty array if notepad isn't running.
            Dim localByName As Process() = Process.GetProcessesByName("notepad")

            ' Get a process on the local computer, using the process id.
            ' This will throw an exception if there is no such process.
            Dim localById As Process = Process.GetProcessById(1234)


            ' Get processes running on a remote computer. Note that this
            ' and all the following calls will timeout and throw an exception
            ' if "myComputer" and 169.0.0.0 do not exist on your local network.

            ' Get all processes on a remote computer.
            Dim remoteAll As Process() = Process.GetProcesses("myComputer")

            ' Get all instances of Notepad running on the specific computer, using machine name.
            Dim remoteByName As Process() = Process.GetProcessesByName("notepad", "myComputer")

            ' Get all instances of Notepad running on the specific computer, using IP address.
            Dim ipByName As Process() = Process.GetProcessesByName("notepad", "169.0.0.0")

            ' Get a process on a remote computer, using the process id and machine name.
            Dim remoteById As Process = Process.GetProcessById(2345, "myComputer")
        End Sub

        Shared Sub Main()
            Dim myProcess As New MyProcess()
            myProcess.BindToRunningProcesses()
        End Sub

    End Class

End Namespace 'MyProcessSample

注釈

このメソッドを使用して、新しい Process コンポーネントの配列を作成し、指定したコンピューターで同じ実行可能ファイルを実行しているすべてのプロセス リソースに関連付けます。 プロセス リソースは、システム リソースを作成するのではなく、アプリケーションによって生成されたProcessコンポーネントに関連付けるのでGetProcessesByName、コンピューター上に既に存在している必要があります。 processNameローカル コンピューターで現在実行されていない実行可能ファイルに 対して を指定できるため、メソッドが返す配列は空にすることができます。

プロセス名は、.exe拡張機能やパスを含まない、Outlook などのプロセスのフレンドリ名です。 GetProcessesByName は、同じ実行可能ファイルに関連付けられているすべてのプロセスを取得および操作するのに役立ちます。 たとえば、実行可能ファイルの実行中のすべてのインスタンスを processName シャットダウンするために、実行可能ファイル名を パラメーターとして渡すことができます。

プロセス Id はシステム上の 1 つのプロセス リソースに固有ですが、 パラメーターで指定されたアプリケーションをローカル コンピューター上の複数のプロセスで processName 実行できます。 したがって、 GetProcessById は最大で 1 つのプロセスを返しますが GetProcessesByName 、関連付けられているすべてのプロセスを含む配列を返します。 標準 API 呼び出しを使用してプロセスを操作する必要がある場合は、これらの各プロセスの識別子を順番に照会できます。 プロセス名だけでプロセス リソースにアクセスすることはできませんが、プロセス リソースに関連付けられているコンポーネントの Process 配列を取得したら、システム リソースを開始、終了、その他の操作を行うことができます。

このオーバーロードを使用すると、ローカル コンピューターとリモート コンピューター上のプロセスを取得できます。 "." を使用して、ローカル コンピューターを指定します。 既定では、ローカル コンピューターを使用する別のオーバーロードが存在します。

リモート コンピューター上のプロセスにアクセスできるのは、プロセスに関する情報 (統計など) を表示することだけです。 リモート コンピューターでプロセスを閉じる、終了する (を使用) Kill、またはプロセスを開始することはできません。

こちらもご覧ください

適用対象

GetProcessesByName(String)

ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs

新しい Process コンポーネントの配列を作成し、指定したプロセス名を共有するローカル コンピューター上のすべてのプロセス リソースに関連付けます。

public:
 static cli::array <System::Diagnostics::Process ^> ^ GetProcessesByName(System::String ^ processName);
public static System.Diagnostics.Process[] GetProcessesByName (string? processName);
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.Process[] GetProcessesByName (string? processName);
public static System.Diagnostics.Process[] GetProcessesByName (string processName);
static member GetProcessesByName : string -> System.Diagnostics.Process[]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member GetProcessesByName : string -> System.Diagnostics.Process[]
Public Shared Function GetProcessesByName (processName As String) As Process()

パラメーター

processName
String

プロセスのフレンドリ名。

戻り値

指定したアプリケーションまたはファイルを実行しているプロセス リソースを表す Process 型の配列。

属性

例外

プロセス情報を取得するために使用するパフォーマンス カウンター API へのアクセスに問題があります。 この例外は、Windows NT、Windows 2000、および Windows XP に固有のものです。

次の例では、現在のプロセス、ローカル コンピューターで実行されているプロセス、ローカル コンピューターで実行されているすべてのメモ帳のインスタンス、およびローカル コンピューター上の特定のプロセスの情報を取得します。 その後、リモート コンピューター上の同じプロセスの情報を取得します。

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;
int main()
{   
   // Get the current process.    
   Process^ currentProcess = Process::GetCurrentProcess();

   // Get all processes running on the local computer.
   array<Process^>^localAll = Process::GetProcesses();

   // Get all instances of Notepad running on the local computer.
   // This will return an empty array if notepad isn't running.
   array<Process^>^localByName = Process::GetProcessesByName("notepad");

   // Get a process on the local computer, using the process id.
   // This will throw an exception if there is no such process.
   Process^ localById = Process::GetProcessById(1234);


   // Get processes running on a remote computer. Note that this
   // and all the following calls will timeout and throw an exception
   // if "myComputer" and 169.0.0.0 do not exist on your local network.

   // Get all processes on a remote computer.
   array<Process^>^remoteAll = Process::GetProcesses("myComputer");

   // Get all instances of Notepad running on the specific computer, using machine name.
   array<Process^>^remoteByName = Process::GetProcessesByName( "notepad", "myComputer" );
   
   // Get all instances of Notepad running on the specific computer, using IP address.
   array<Process^>^ipByName = Process::GetProcessesByName( "notepad", "169.0.0.0" );
   
   // Get a process on a remote computer, using the process id and machine name.
   Process^ remoteById = Process::GetProcessById( 2345, "myComputer" );
}
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        void BindToRunningProcesses()
        {
            // Get the current process.
            Process currentProcess = Process.GetCurrentProcess();

            // Get all processes running on the local computer.
            Process[] localAll = Process.GetProcesses();

            // Get all instances of Notepad running on the local computer.
            // This will return an empty array if notepad isn't running.
            Process[] localByName = Process.GetProcessesByName("notepad");

            // Get a process on the local computer, using the process id.
            // This will throw an exception if there is no such process.
            Process localById = Process.GetProcessById(1234);

            // Get processes running on a remote computer. Note that this
            // and all the following calls will timeout and throw an exception
            // if "myComputer" and 169.0.0.0 do not exist on your local network.

            // Get all processes on a remote computer.
            Process[] remoteAll = Process.GetProcesses("myComputer");

            // Get all instances of Notepad running on the specific computer, using machine name.
            Process[] remoteByName = Process.GetProcessesByName("notepad", "myComputer");

            // Get all instances of Notepad running on the specific computer, using IP address.
            Process[] ipByName = Process.GetProcessesByName("notepad", "169.0.0.0");

            // Get a process on a remote computer, using the process id and machine name.
            Process remoteById = Process.GetProcessById(2345, "myComputer");
        }

        static void Main()
        {
            MyProcess myProcess = new MyProcess();
            myProcess.BindToRunningProcesses();
        }
    }
}
Imports System.Diagnostics
Imports System.ComponentModel

Namespace MyProcessSample
    Class MyProcess
        Sub BindToRunningProcesses()
            ' Get the current process. You can use currentProcess from this point
            ' to access various properties and call methods to control the process.
            Dim currentProcess As Process = Process.GetCurrentProcess()

            ' Get all processes running on the local computer.
            Dim localAll As Process() = Process.GetProcesses()

            ' Get all instances of Notepad running on the local computer.
            ' This will return an empty array if notepad isn't running.
            Dim localByName As Process() = Process.GetProcessesByName("notepad")

            ' Get a process on the local computer, using the process id.
            ' This will throw an exception if there is no such process.
            Dim localById As Process = Process.GetProcessById(1234)


            ' Get processes running on a remote computer. Note that this
            ' and all the following calls will timeout and throw an exception
            ' if "myComputer" and 169.0.0.0 do not exist on your local network.

            ' Get all processes on a remote computer.
            Dim remoteAll As Process() = Process.GetProcesses("myComputer")

            ' Get all instances of Notepad running on the specific computer, using machine name.
            Dim remoteByName As Process() = Process.GetProcessesByName("notepad", "myComputer")

            ' Get all instances of Notepad running on the specific computer, using IP address.
            Dim ipByName As Process() = Process.GetProcessesByName("notepad", "169.0.0.0")

            ' Get a process on a remote computer, using the process id and machine name.
            Dim remoteById As Process = Process.GetProcessById(2345, "myComputer")
        End Sub

        Shared Sub Main()
            Dim myProcess As New MyProcess()
            myProcess.BindToRunningProcesses()
        End Sub

    End Class

End Namespace 'MyProcessSample

注釈

このメソッドを使用して、新しい Process コンポーネントの配列を作成し、ローカル コンピューターで同じ実行可能ファイルを実行しているすべてのプロセス リソースに関連付けます。 プロセス リソースは、システム リソースを作成するのではなく、アプリケーションによって生成されたProcessコンポーネントに関連付けるのでGetProcessesByName、コンピューター上に既に存在している必要があります。 processNameローカル コンピューターで現在実行されていない実行可能ファイルに 対して を指定できるため、メソッドが返す配列は空にすることができます。

プロセス名は、.exe拡張機能やパスを含まない、Outlook などのプロセスのフレンドリ名です。 GetProcessesByName は、同じ実行可能ファイルに関連付けられているすべてのプロセスを取得および操作するのに役立ちます。 たとえば、実行可能ファイルの実行中のすべてのインスタンスを processName シャットダウンするために、実行可能ファイル名を パラメーターとして渡すことができます。

プロセス Id はシステム上の 1 つのプロセス リソースに固有ですが、 パラメーターで指定されたアプリケーションをローカル コンピューター上の複数のプロセスで processName 実行できます。 したがって、 GetProcessById は最大で 1 つのプロセスを返しますが GetProcessesByName 、関連付けられているすべてのプロセスを含む配列を返します。 標準 API 呼び出しを使用してプロセスを操作する必要がある場合は、これらの各プロセスの識別子を順番に照会できます。 プロセス名だけでプロセス リソースにアクセスすることはできませんが、プロセス リソースに関連付けられているコンポーネントの Process 配列を取得したら、システム リソースを開始、終了、その他の操作を行うことができます。

こちらもご覧ください

適用対象