Process.GetProcessById Metoda

Definice

Vytvoří novou Process komponentu a přidruží ji k existujícímu prostředku procesu, který zadáte.

Přetížení

Name Description
GetProcessById(Int32)

Vrátí novou komponentu Process vzhledem k identifikátoru procesu v místním počítači.

GetProcessById(Int32, String)

Vrátí novou komponentu Process s identifikátorem procesu a názvem počítače v síti.

GetProcessById(Int32)

Zdroj:
Process.cs
Zdroj:
Process.cs
Zdroj:
Process.cs
Zdroj:
Process.cs
Zdroj:
Process.cs

Vrátí novou komponentu Process vzhledem k identifikátoru procesu v místním počítači.

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

Parametry

processId
Int32

Systémový jedinečný identifikátor prostředku procesu.

Návraty

Komponenta Process přidružená k prostředku místního procesu identifikovaného parametrem processId .

Výjimky

Proces určený parametrem processId není spuštěný. Platnost identifikátoru může vypršena.

Příklady

Následující příklad načte informace o aktuálním procesu, procesy spuštěné v místním počítači, všechny instance Poznámkového bloku spuštěné v místním počítači a konkrétní proces na místním počítači. Potom načte informace pro stejné procesy ve vzdáleném počítači.

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

Poznámky

Pomocí této metody vytvořte novou Process komponentu a přidružte ji k prostředku procesu v místním počítači. Prostředek procesu již musí existovat v počítači, protože GetProcessById(Int32) nevytvoří systémový prostředek, ale spíše přidruží prostředek k komponentě generované Process aplikací. Proces Id lze načíst pouze pro proces, který je aktuálně spuštěný v počítači. Po ukončení procesu vyvolá výjimku, GetProcessById(Int32) pokud jí předáte identifikátor s vypršenou platností.

V každém konkrétním počítači je identifikátor procesu jedinečný. GetProcessById(Int32) vrátí maximálně jeden proces. Pokud chcete získat všechny procesy spuštěné konkrétní aplikace, použijte GetProcessesByName(String). Pokud na počítači se spuštěnou zadanou aplikací existuje více procesů, GetProcessesByName(String) vrátí pole obsahující všechny přidružené procesy. Každý z těchto procesů můžete následně dotazovat na jeho identifikátor. Identifikátor procesu lze zobrazit na panelu Processes správce úloh Windows. Ve PID sloupci se zobrazí identifikátor procesu, který je přiřazený procesu.

Parametr processId je Int32 (32bitové celé číslo se znaménkem), i když základní rozhraní API Windows používá pro podobná rozhraní API DWORD (bez znaménka 32bitové celé číslo). To je z historických důvodů.

Viz také

Platí pro

GetProcessById(Int32, String)

Zdroj:
Process.cs
Zdroj:
Process.cs
Zdroj:
Process.cs
Zdroj:
Process.cs
Zdroj:
Process.cs

Vrátí novou komponentu Process s identifikátorem procesu a názvem počítače v síti.

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

Parametry

processId
Int32

Systémový jedinečný identifikátor prostředku procesu.

machineName
String

Název počítače v síti.

Návraty

Komponenta Process přidružená k prostředku vzdáleného procesu identifikovaného parametrem processId .

Výjimky

Proces určený parametrem processId není spuštěný. Platnost identifikátoru může vypršena.

nebo

machineName Syntaxe parametru je neplatná. Název může mít nulovou délku (0).

Parametr machineName je null.

Příklady

Následující příklad načte informace o aktuálním procesu, procesy spuštěné v místním počítači, všechny instance Poznámkového bloku spuštěné v místním počítači a konkrétní proces na místním počítači. Potom načte informace pro stejné procesy ve vzdáleném počítači.

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

Poznámky

Pomocí této metody vytvořte novou Process komponentu a přidružte ji k prostředku procesu ve vzdáleném počítači v síti. Prostředek procesu již musí existovat v zadaném počítači, protože GetProcessById(Int32, String) nevytvoří systémový prostředek, ale spíše přidruží prostředek k komponentě generované Process aplikací. Proces Id lze načíst pouze pro proces, který je aktuálně spuštěný v počítači. Po ukončení procesu vyvolá výjimku, GetProcessById(Int32, String) pokud jí předáte identifikátor s vypršenou platností.

V každém konkrétním počítači je identifikátor procesu jedinečný. GetProcessById(Int32, String) vrátí maximálně jeden proces. Pokud chcete získat všechny procesy spuštěné konkrétní aplikace, použijte GetProcessesByName(String). Pokud na počítači se spuštěnou zadanou aplikací existuje více procesů, GetProcessesByName(String) vrátí pole obsahující všechny přidružené procesy. Každý z těchto procesů můžete následně dotazovat na jeho identifikátor. Identifikátor procesu lze zobrazit na panelu Processes správce úloh Windows. Ve PID sloupci se zobrazí identifikátor procesu, který je přiřazený procesu.

Pokud nezadáte , machineNamepoužije se místní počítač. Případně můžete místní počítač zadat nastavením machineName hodnoty "" nebo prázdného řetězce ("").

Parametr processId je Int32 (32bitové celé číslo se znaménkem), i když základní rozhraní API Windows používá pro podobná rozhraní API DWORD (bez znaménka 32bitové celé číslo). To je z historických důvodů.

Viz také

Platí pro