Process.GetProcessesByName 메서드

정의

Process 구성 요소로 이루어진 새 배열을 만들어 지정한 프로세스 이름을 공유하는 모든 기존 프로세스 리소스에 연결합니다.

오버로드

GetProcessesByName(String, String)

Process 구성 요소로 이루어진 새 배열을 만들어 지정한 프로세스 이름을 공유하는 원격 컴퓨터에 있는 모든 프로세스 리소스에 연결합니다.

GetProcessesByName(String)

Process 구성 요소로 이루어진 새 배열을 만들어 지정한 프로세스 이름을 공유하는 로컬 컴퓨터의 모든 프로세스 리소스에 연결합니다.

GetProcessesByName(String, String)

Source:
Process.Linux.cs
Source:
Process.Linux.cs
Source:
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 구성 요소의 배열을 만들고 지정된 컴퓨터에서 동일한 실행 파일을 실행하는 모든 프로세스 리소스와 연결합니다. 때문에 컴퓨터의 프로세스 리소스에 이미 존재 해야 합니다 GetProcessesByName 시스템 리소스를 만들지는 않지만 대신 애플리케이션에서 생성 된 연결 Process 구성 요소입니다. processName 현재 로컬 컴퓨터에서 실행되고 있지 않은 실행 파일에 대해 를 지정할 수 있으므로 메서드가 반환하는 배열이 비어 있을 수 있습니다.

프로세스 이름은 .exe 확장 또는 경로를 포함하지 않는 Outlook과 같은 프로세스의 이름입니다. GetProcessesByName 는 동일한 실행 파일과 연결된 모든 프로세스를 가져오고 조작하는 데 유용합니다. 예를 들어 실행 파일의 실행 중인 인스턴스를 모두 종료하기 위해 실행 파일 이름을 매개 변수로 processName 전달할 수 있습니다.

하지만 프로세스 Id 은 시스템에서 단일 프로세스 리소스에 고유한 로컬 컴퓨터의 여러 프로세스 실행 될 수 있습니다 지정 된 애플리케이션과 processName 매개 변수입니다. 따라서 GetProcessById 는 최대 하나의 프로세스를 반환하지만 GetProcessesByName 연결된 모든 프로세스가 포함된 배열을 반환합니다. 표준 API 호출을 사용하여 프로세스를 조작해야 하는 경우 이러한 각 프로세스를 차례로 해당 식별자에 대해 쿼리할 수 있습니다. 프로세스 이름만으로는 프로세스 리소스에 액세스할 수 없지만 프로세스 리소스와 연결된 구성 요소 배열 Process 을 검색한 후에는 시스템 리소스를 시작, 종료 및 조작할 수 있습니다.

이 오버로드를 사용하여 로컬 컴퓨터와 원격 컴퓨터에서 프로세스를 가져올 수 있습니다. "."를 사용하여 로컬 컴퓨터를 지정합니다. 기본적으로 로컬 컴퓨터를 사용하는 또 다른 오버로드가 있습니다.

원격 컴퓨터의 프로세스에만 액세스하여 프로세스에 대한 통계와 같은 정보를 볼 수 있습니다. 원격 컴퓨터에서 프로세스를 닫거나 종료하거나(사용) Kill시작할 수 없습니다.

추가 정보

적용 대상

GetProcessesByName(String)

Source:
Process.cs
Source:
Process.cs
Source:
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 구성 요소의 배열을 만들고 로컬 컴퓨터에서 동일한 실행 파일을 실행하는 모든 프로세스 리소스와 연결합니다. 때문에 컴퓨터의 프로세스 리소스에 이미 존재 해야 합니다 GetProcessesByName 시스템 리소스를 만들지는 않지만 대신 애플리케이션에서 생성 된 연결 Process 구성 요소입니다. processName 현재 로컬 컴퓨터에서 실행되고 있지 않은 실행 파일에 대해 를 지정할 수 있으므로 메서드가 반환하는 배열이 비어 있을 수 있습니다.

프로세스 이름은 .exe 확장 또는 경로를 포함하지 않는 Outlook과 같은 프로세스의 이름입니다. GetProcessesByName 는 동일한 실행 파일과 연결된 모든 프로세스를 가져오고 조작하는 데 유용합니다. 예를 들어 실행 파일의 실행 중인 인스턴스를 모두 종료하기 위해 실행 파일 이름을 매개 변수로 processName 전달할 수 있습니다.

하지만 프로세스 Id 은 시스템에서 단일 프로세스 리소스에 고유한 로컬 컴퓨터의 여러 프로세스 실행 될 수 있습니다 지정 된 애플리케이션과 processName 매개 변수입니다. 따라서 GetProcessById 는 최대 하나의 프로세스를 반환하지만 GetProcessesByName 연결된 모든 프로세스가 포함된 배열을 반환합니다. 표준 API 호출을 사용하여 프로세스를 조작해야 하는 경우 이러한 각 프로세스를 차례로 해당 식별자에 대해 쿼리할 수 있습니다. 프로세스 이름만으로는 프로세스 리소스에 액세스할 수 없지만 프로세스 리소스와 연결된 구성 요소 배열 Process 을 검색한 후에는 시스템 리소스를 시작, 종료 및 조작할 수 있습니다.

추가 정보

적용 대상