Process.GetProcesses 메서드

정의

Process 구성 요소의 배열을 만들고 기존 프로세스 리소스와 연결합니다.

오버로드

Name Description
GetProcesses()

로컬 컴퓨터의 각 프로세스 리소스에 대한 새 Process 구성 요소를 만듭니다.

GetProcesses(String)

지정된 컴퓨터의 각 프로세스 리소스에 대한 새 Process 구성 요소를 만듭니다.

GetProcesses()

로컬 컴퓨터의 각 프로세스 리소스에 대한 새 Process 구성 요소를 만듭니다.

public:
 static cli::array <System::Diagnostics::Process ^> ^ GetProcesses();
public static System.Diagnostics.Process[] GetProcesses();
static member GetProcesses : unit -> System.Diagnostics.Process[]
Public Shared Function GetProcesses () As Process()

반품

로컬 컴퓨터에서 실행되는 모든 프로세스 리소스를 나타내는 형식 Process 의 배열입니다.

예제

다음 예제에서는 현재 프로세스의 정보, 로컬 컴퓨터에서 실행 중인 프로세스, 로컬 컴퓨터에서 실행 중인 메모장의 모든 인스턴스 및 로컬 컴퓨터의 특정 프로세스를 검색합니다. 그런 다음 원격 컴퓨터에서 동일한 프로세스에 대한 정보를 검색합니다.

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();
        }
    }
}
open System.Diagnostics

// Get the current process.
let currentProcess = Process.GetCurrentProcess()

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

// Get all instances of Notepad running on the local computer.
// This will return an empty array if notepad isn't running.
let 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.
let 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.
let remoteAll = Process.GetProcesses "myComputer"

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

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

// Get a process on a remote computer, using the process id and machine name.
let remoteById = Process.GetProcessById(2345, "myComputer")
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 구성 요소와 리소스를 연결하기 때문에 GetProcesses 프로세스 리소스가 로컬 컴퓨터에 이미 있어야 합니다. 운영 체제 자체가 백그라운드 프로세스를 실행하고 있으므로 이 배열은 비어 있는 것이 없습니다.

컴퓨터에서 실행 중인 모든 프로세스를 검색하지 않으려는 경우 또는 GetProcessesByName 메서드를 사용하여 GetProcessById 해당 수를 제한할 수 있습니다. GetProcessById 는 메서드에 Process 전달하는 프로세스 식별자에 의해 시스템에서 식별되는 프로세스와 연결된 구성 요소를 만듭니다. GetProcessesByName 는 연결된 프로세스 리소스가 메서드에 전달하는 실행 파일을 공유하는 구성 요소의 배열 Process 을 만듭니다.

Note

서비스 호스트 프로세스(svchost.exe)의 동일한 인스턴스 내에서 여러 Windows 서비스를 로드할 수 있습니다. GetProcesses는 이러한 개별 서비스를 식별하지 않습니다. 이 경우 다음을 참조하세요 GetServices.

추가 정보

적용 대상

GetProcesses(String)

지정된 컴퓨터의 각 프로세스 리소스에 대한 새 Process 구성 요소를 만듭니다.

public:
 static cli::array <System::Diagnostics::Process ^> ^ GetProcesses(System::String ^ machineName);
public static System.Diagnostics.Process[] GetProcesses(string machineName);
static member GetProcesses : string -> System.Diagnostics.Process[]
Public Shared Function GetProcesses (machineName As String) As Process()

매개 변수

machineName
String

프로세스 목록을 읽을 컴퓨터입니다.

반품

지정된 컴퓨터에서 실행되는 모든 프로세스 리소스를 나타내는 형식 Process 의 배열입니다.

예외

machineName 매개 변수 구문이 잘못되었습니다. 길이가 0일 수 있습니다.

매개 변수는 machineName .입니다 null.

운영 체제 플랫폼은 원격 컴퓨터에서 이 작업을 지원하지 않습니다.

프로세스 정보를 가져오는 데 사용되는 성능 카운터 API에 액세스하는 데 문제가 있습니다. 이 예외는 Windows NT, Windows 2000 및 Windows XP 관련이 있습니다.

기본 시스템 API에 액세스하는 동안 문제가 발생했습니다.

예제

다음 예제에서는 현재 프로세스의 정보, 로컬 컴퓨터에서 실행 중인 프로세스, 로컬 컴퓨터에서 실행 중인 메모장의 모든 인스턴스 및 로컬 컴퓨터의 특정 프로세스를 검색합니다. 그런 다음 원격 컴퓨터에서 동일한 프로세스에 대한 정보를 검색합니다.

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();
        }
    }
}
open System.Diagnostics

// Get the current process.
let currentProcess = Process.GetCurrentProcess()

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

// Get all instances of Notepad running on the local computer.
// This will return an empty array if notepad isn't running.
let 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.
let 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.
let remoteAll = Process.GetProcesses "myComputer"

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

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

// Get a process on a remote computer, using the process id and machine name.
let remoteById = Process.GetProcessById(2345, "myComputer")
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 구성 요소와 리소스를 연결하기 때문에 GetProcesses 프로세스 리소스가 로컬 컴퓨터에 이미 있어야 합니다. 운영 체제 자체가 백그라운드 프로세스를 실행하고 있으므로 이 배열은 비어 있는 것이 없습니다.

컴퓨터에서 실행 중인 모든 프로세스를 검색하지 않으려는 경우 또는 GetProcessesByName 메서드를 사용하여 GetProcessById 해당 수를 제한할 수 있습니다. GetProcessById 는 메서드에 Process 전달하는 프로세스 식별자에 의해 시스템에서 식별되는 프로세스와 연결된 구성 요소를 만듭니다. GetProcessesByName 는 연결된 프로세스 리소스가 메서드에 전달하는 실행 파일을 공유하는 구성 요소의 배열 Process 을 만듭니다.

이 메서드 오버 GetProcesses 로드는 일반적으로 네트워크의 원격 컴퓨터에서 실행되는 프로세스 리소스 목록을 검색하는 데 사용되지만 "."를 전달하여 로컬 컴퓨터를 지정할 수 있습니다.

Note

서비스 호스트 프로세스(svchost.exe)의 동일한 인스턴스 내에서 여러 Windows 서비스를 로드할 수 있습니다. GetProcesses는 이러한 개별 서비스를 식별하지 않습니다. 이 경우 다음을 참조하세요 GetServices.

추가 정보

적용 대상