Process.GetProcessById Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Erstellt eine neue Process Komponente und ordnet sie der von Ihnen angegebenen vorhandenen Prozessressource zu.
Überlädt
| Name | Beschreibung |
|---|---|
| GetProcessById(Int32) |
Gibt eine neue Process Komponente zurück, wobei der Bezeichner eines Prozesses auf dem lokalen Computer angegeben ist. |
| GetProcessById(Int32, String) |
Gibt eine neue Process Komponente zurück, die einen Prozessbezeichner und den Namen eines Computers im Netzwerk erhält. |
GetProcessById(Int32)
Gibt eine neue Process Komponente zurück, wobei der Bezeichner eines Prozesses auf dem lokalen Computer angegeben ist.
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
Parameter
- processId
- Int32
Der systemspezifische Bezeichner einer Prozessressource.
Gibt zurück
Eine Process Komponente, die der lokalen Prozessressource zugeordnet ist, die processId vom Parameter identifiziert wird.
Ausnahmen
Der durch den processId Parameter angegebene Prozess wird nicht ausgeführt. Der Bezeichner ist möglicherweise abgelaufen.
Beispiele
Im folgenden Beispiel werden Informationen des aktuellen Prozesses, Prozesse abgerufen, die auf dem lokalen Computer ausgeführt werden, alle Instanzen von Editor, die auf dem lokalen Computer ausgeführt werden, und ein bestimmter Prozess auf dem lokalen Computer. Anschließend werden Informationen für dieselben Prozesse auf einem Remotecomputer abgerufen.
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
Hinweise
Verwenden Sie diese Methode, um eine neue Process Komponente zu erstellen und sie einer Prozessressource auf dem lokalen Computer zuzuordnen. Die Prozessressource muss bereits auf dem Computer vorhanden sein, da GetProcessById(Int32) keine Systemressource erstellt wird, sondern eine Ressource einer vom Anwendung generierten Process Komponente zugeordnet wird. Ein Prozess Id kann nur für einen Prozess abgerufen werden, der derzeit auf dem Computer ausgeführt wird. Nachdem der Prozess beendet wurde, wird eine Ausnahme ausgelöst, GetProcessById(Int32) wenn Sie ihn an einen abgelaufenen Bezeichner übergeben.
Auf einem bestimmten Computer ist der Bezeichner eines Prozesses eindeutig.
GetProcessById(Int32) gibt höchstens einen Prozess zurück. Wenn Sie alle Prozesse abrufen möchten, die eine bestimmte Anwendung ausführen, verwenden Sie GetProcessesByName(String). Wenn auf dem Computer, auf dem die angegebene Anwendung ausgeführt wird, mehrere Prozesse vorhanden sind, wird ein Array zurückgegeben, GetProcessesByName(String) das alle zugeordneten Prozesse enthält. Sie können jeden dieser Prozesse wiederum nach seinem Bezeichner abfragen. Der Prozessbezeichner kann im Bereich Processes des Windows Task-Managers angezeigt werden. In der PID Spalte wird der Prozessbezeichner angezeigt, der einem Prozess zugewiesen ist.
Der parameter processId ist ein Int32 (eine 32-Bit-Ganzzahl), obwohl die zugrunde liegende Windows-API eine DWORD (eine nicht signierte 32-Bit-Ganzzahl) für ähnliche APIs verwendet. Dies ist aus historischen Gründen.
Weitere Informationen
Gilt für:
GetProcessById(Int32, String)
Gibt eine neue Process Komponente zurück, die einen Prozessbezeichner und den Namen eines Computers im Netzwerk erhält.
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
Parameter
- processId
- Int32
Der systemspezifische Bezeichner einer Prozessressource.
- machineName
- String
Der Name eines Computers im Netzwerk.
Gibt zurück
Eine Process Komponente, die einer Remoteprozessressource zugeordnet ist, die durch den processId Parameter identifiziert wird.
Ausnahmen
Der durch den processId Parameter angegebene Prozess wird nicht ausgeführt. Der Bezeichner ist möglicherweise abgelaufen.
-oder-
Die machineName Parametersyntax ist ungültig. Der Name hat möglicherweise die Länge Null (0).
Der machineName Parameter ist null.
Beispiele
Im folgenden Beispiel werden Informationen des aktuellen Prozesses, Prozesse abgerufen, die auf dem lokalen Computer ausgeführt werden, alle Instanzen von Editor, die auf dem lokalen Computer ausgeführt werden, und ein bestimmter Prozess auf dem lokalen Computer. Anschließend werden Informationen für dieselben Prozesse auf einem Remotecomputer abgerufen.
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
Hinweise
Verwenden Sie diese Methode, um eine neue Process Komponente zu erstellen und sie einer Prozessressource auf einem Remotecomputer im Netzwerk zuzuordnen. Die Prozessressource muss bereits auf dem angegebenen Computer vorhanden sein, da GetProcessById(Int32, String) keine Systemressource erstellt wird, sondern eine Ressource einer vom Anwendung generierten Process Komponente zugeordnet wird. Ein Prozess Id kann nur für einen Prozess abgerufen werden, der derzeit auf dem Computer ausgeführt wird. Nachdem der Prozess beendet wurde, wird eine Ausnahme ausgelöst, GetProcessById(Int32, String) wenn Sie ihn an einen abgelaufenen Bezeichner übergeben.
Auf einem bestimmten Computer ist der Bezeichner eines Prozesses eindeutig.
GetProcessById(Int32, String) gibt höchstens einen Prozess zurück. Wenn Sie alle Prozesse abrufen möchten, die eine bestimmte Anwendung ausführen, verwenden Sie GetProcessesByName(String). Wenn auf dem Computer, auf dem die angegebene Anwendung ausgeführt wird, mehrere Prozesse vorhanden sind, wird ein Array zurückgegeben, GetProcessesByName(String) das alle zugeordneten Prozesse enthält. Sie können jeden dieser Prozesse wiederum nach seinem Bezeichner abfragen. Der Prozessbezeichner kann im Bereich Processes des Windows Task-Managers angezeigt werden. In der PID Spalte wird der Prozessbezeichner angezeigt, der einem Prozess zugewiesen ist.
Wenn Sie keinen Angeben, machineNamewird der lokale Computer verwendet. Alternativ können Sie den lokalen Computer angeben, indem Sie den Wert "." oder eine leere Zeichenfolge ("") festlegen machineName .
Der parameter processId ist ein Int32 (eine 32-Bit-Ganzzahl), obwohl die zugrunde liegende Windows-API eine DWORD (eine nicht signierte 32-Bit-Ganzzahl) für ähnliche APIs verwendet. Dies ist aus historischen Gründen.