Process.GetProcessById 메서드

정의

Process 구성 요소를 만들어 사용자가 지정한 기존 프로세스 리소스에 연결합니다.

오버로드

GetProcessById(Int32)

로컬 컴퓨터의 프로세서에 대한 식별자가 주어지면 새 Process 구성 요소를 반환합니다.

GetProcessById(Int32, String)

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

GetProcessById(Int32)

Source:
Process.cs
Source:
Process.cs
Source:
Process.cs

로컬 컴퓨터의 프로세서에 대한 식별자가 주어지면 새 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

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

반환

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

예외

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

예제

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

#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 구성 요소를 만들고 로컬 컴퓨터의 프로세스 리소스와 연결합니다. 때문에 컴퓨터의 프로세스 리소스 이미 존재 해야 합니다 GetProcessById(Int32) 시스템 리소스를 만들지는 않지만 대신 애플리케이션에서 생성 된 리소스를 연결 Process 구성 요소입니다. 현재 컴퓨터에서 실행 중인 프로세스에 대해서만 프로세스를 Id 검색할 수 있습니다. 프로세스가 종료된 GetProcessById(Int32) 후 만료된 식별자를 전달하면 예외를 throw합니다.

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

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

추가 정보

적용 대상

GetProcessById(Int32, String)

Source:
Process.cs
Source:
Process.cs
Source:
Process.cs

프로세스 식별자 및 네트워크에 있는 컴퓨터의 이름이 주어지면 새 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

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

반환

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

예외

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

또는

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

machineName 매개 변수가 null인 경우

예제

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

#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 구성 요소를 만들고 네트워크의 원격 컴퓨터에서 프로세스 리소스와 연결합니다. 때문에 지정한 컴퓨터의 프로세스 리소스 이미 존재 해야 합니다 GetProcessById(Int32, String) 시스템 리소스를 만들지는 않지만 대신 애플리케이션에서 생성 된 리소스를 연결 Process 구성 요소입니다. 현재 컴퓨터에서 실행 중인 프로세스에 대해서만 프로세스를 Id 검색할 수 있습니다. 프로세스가 종료된 GetProcessById(Int32, String) 후 만료된 식별자를 전달하면 예외를 throw합니다.

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

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

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

추가 정보

적용 대상