Process.GetProcessById 메서드

정의

Process 구성 요소를 만들고 지정한 기존 프로세스 리소스와 연결합니다.

오버로드

Name Description
GetProcessById(Int32)

로컬 컴퓨터에서 프로세스의 식별자를 지정하여 새 Process 구성 요소를 반환합니다.

GetProcessById(Int32, String)

네트워크에 있는 컴퓨터의 이름 및 프로세스 식별자를 지정하여 새 Process 구성 요소를 반환합니다.

GetProcessById(Int32)

로컬 컴퓨터에서 프로세스의 식별자를 지정하여 새 Process 구성 요소를 반환합니다.

public:
 static System::Diagnostics::Process ^ GetProcessById(int processId);
public static System.Diagnostics.Process GetProcessById(int processId);
static member GetProcessById : int -> System.Diagnostics.Process
Public Shared Function GetProcessById (processId As Integer) As Process

매개 변수

processId
Int32

프로세스 리소스의 시스템 고유 식별자입니다.

반품

Process 매개 변수로 식별 processId 되는 로컬 프로세스 리소스와 연결된 구성 요소입니다.

예외

매개 변수에 지정된 processId 프로세스가 실행되고 있지 않습니다. 식별자가 만료되었을 수 있습니다.

예제

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

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 구성 요소와 리소스를 연결하기 때문에 GetProcessById(Int32) 컴퓨터에 이미 있어야 합니다. Id 현재 컴퓨터에서 실행 중인 프로세스에 대해서만 프로세스를 검색할 수 있습니다. 프로세스가 종료된 GetProcessById(Int32) 후 만료된 식별자를 전달하면 예외를 throw합니다.

특정 컴퓨터에서 프로세스의 식별자는 고유합니다. GetProcessById(Int32) 는 최대 하나의 프로세스를 반환합니다. 특정 애플리케이션을 실행하는 모든 프로세스를 얻으려면 .를 사용합니다 GetProcessesByName(String). 지정된 애플리케이션 GetProcessesByName(String) 을 실행하는 컴퓨터에 여러 프로세스가 있는 경우 연결된 모든 프로세스가 포함된 배열을 반환합니다. 이러한 각 프로세스에서 해당 식별자를 차례로 쿼리할 수 있습니다. 프로세스 식별자는 Windows 작업 관리자의 Processes 패널에서 볼 수 있습니다. 열에는 PID 프로세스에 할당된 프로세스 식별자가 표시됩니다.

processId 매개 변수는 Int32(32비트 부호 있는 정수)이지만 기본 Windows API는 유사한 API에 DWORD(부호 없는 32비트 정수)를 사용합니다. 이것은 역사적 이유입니다.

추가 정보

적용 대상

GetProcessById(Int32, String)

네트워크에 있는 컴퓨터의 이름 및 프로세스 식별자를 지정하여 새 Process 구성 요소를 반환합니다.

public:
 static System::Diagnostics::Process ^ GetProcessById(int processId, System::String ^ machineName);
public static System.Diagnostics.Process GetProcessById(int processId, string machineName);
static member GetProcessById : int * string -> System.Diagnostics.Process
Public Shared Function GetProcessById (processId As Integer, machineName As String) As Process

매개 변수

processId
Int32

프로세스 리소스의 시스템 고유 식별자입니다.

machineName
String

네트워크에 있는 컴퓨터의 이름입니다.

반품

Process 매개 변수로 식별 processId 되는 원격 프로세스 리소스와 연결된 구성 요소입니다.

예외

매개 변수에 지정된 processId 프로세스가 실행되고 있지 않습니다. 식별자가 만료되었을 수 있습니다.

-또는-

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

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

예제

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

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 구성 요소와 리소스를 연결하기 때문에 GetProcessById(Int32, String) 프로세스 리소스가 지정된 컴퓨터에 이미 있어야 합니다. Id 현재 컴퓨터에서 실행 중인 프로세스에 대해서만 프로세스를 검색할 수 있습니다. 프로세스가 종료된 GetProcessById(Int32, String) 후 만료된 식별자를 전달하면 예외를 throw합니다.

특정 컴퓨터에서 프로세스의 식별자는 고유합니다. GetProcessById(Int32, String) 는 최대 하나의 프로세스를 반환합니다. 특정 애플리케이션을 실행하는 모든 프로세스를 얻으려면 .를 사용합니다 GetProcessesByName(String). 지정된 애플리케이션 GetProcessesByName(String) 을 실행하는 컴퓨터에 여러 프로세스가 있는 경우 연결된 모든 프로세스가 포함된 배열을 반환합니다. 이러한 각 프로세스에서 해당 식별자를 차례로 쿼리할 수 있습니다. 프로세스 식별자는 Windows 작업 관리자의 Processes 패널에서 볼 수 있습니다. 열에는 PID 프로세스에 할당된 프로세스 식별자가 표시됩니다.

지정 machineName하지 않으면 로컬 컴퓨터가 사용됩니다. 또는 값 "." 또는 빈 문자열("")로 설정 machineName 하여 로컬 컴퓨터를 지정할 수 있습니다.

processId 매개 변수는 Int32(32비트 부호 있는 정수)이지만 기본 Windows API는 유사한 API에 DWORD(부호 없는 32비트 정수)를 사용합니다. 이것은 역사적 이유입니다.

추가 정보

적용 대상