Process.GetProcessesByName Methode

Definition

Erstellt ein Array neuer Process-Komponenten und ordnet diese den vorhandenen Prozessressourcen zu, die den angegebenen Prozessnamen gemeinsam verwenden.

Überlädt

GetProcessesByName(String, String)

Erstellt ein Array neuer Process-Komponenten und ordnet diese allen Prozessressourcen auf einem Remotecomputer zu, die den angegebenen Prozessnamen gemeinsam verwenden.

GetProcessesByName(String)

Erstellt ein Array neuer Process-Komponenten und ordnet diese allen Prozessressourcen auf dem lokalen Computer zu, die den angegebenen Prozessnamen gemeinsam verwenden.

GetProcessesByName(String, String)

Erstellt ein Array neuer Process-Komponenten und ordnet diese allen Prozessressourcen auf einem Remotecomputer zu, die den angegebenen Prozessnamen gemeinsam verwenden.

public:
 static cli::array <System::Diagnostics::Process ^> ^ GetProcessesByName(System::String ^ processName, System::String ^ machineName);
public static System.Diagnostics.Process[] GetProcessesByName (string? processName, string machineName);
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.Process[] GetProcessesByName (string? processName, string machineName);
public static System.Diagnostics.Process[] GetProcessesByName (string processName, string machineName);
static member GetProcessesByName : string * string -> System.Diagnostics.Process[]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member GetProcessesByName : string * string -> System.Diagnostics.Process[]
Public Shared Function GetProcessesByName (processName As String, machineName As String) As Process()

Parameter

processName
String

Der angezeigte Name des Prozesses.

machineName
String

Der Name eines Computers im Netzwerk.

Gibt zurück

Ein Array vom Typ Process, das die Prozessressourcen darstellt, die die angegebene Anwendung oder Datei ausführen.

Attribute

Ausnahmen

Die Syntax des machineName-Parameters ist ungültig. Sie kann die Länge 0 (null) haben.

Der machineName-Parameter ist null.

Die Betriebssystemplattform unterstützt diesen Vorgang nicht auf Remotecomputern.

Der Versuch, eine Verbindung zu machineName aufzubauen, ist fehlgeschlagen.

- oder -

Beim Zugriff auf die Leistungsindikator-APIs zum Abrufen von Prozessinformationen treten Probleme auf. Diese Ausnahme tritt nur unter Windows NT, Windows 2000 und Windows XP auf.

Beim Zugriff auf eine zugrunde liegende System-API ist ein Problem aufgetreten.

Beispiele

Im folgenden Beispiel werden Informationen zum aktuellen Prozess, prozesse, 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 abgerufen. Anschließend werden Informationen für die gleichen Prozesse auf einem Remotecomputer abgerufen.

#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

Hinweise

Verwenden Sie diese Methode, um ein Array neuer Process Komponenten zu erstellen und sie allen Prozessressourcen zuzuordnen, die dieselbe ausführbare Datei auf dem angegebenen Computer ausführen. Die Prozessressourcen müssen bereits auf dem Computer vorhanden sein, da GetProcessesByName keine Systemressourcen erstellt, sondern mit anwendungsgenerierten Komponenten verknüpft Process werden. Ein processName kann für eine ausführbare Datei angegeben werden, die derzeit nicht auf dem lokalen Computer ausgeführt wird, sodass das von der Methode zurückgegebene Array leer sein kann.

Der Prozessname ist ein Anzeigename für den Prozess, z. B. Outlook, der die .exe-Erweiterung oder den Pfad nicht enthält. GetProcessesByName ist hilfreich, um alle Prozesse zu erhalten und zu bearbeiten, die derselben ausführbaren Datei zugeordnet sind. Sie können beispielsweise einen ausführbaren Dateinamen als processName Parameter übergeben, um alle ausgeführten Instanzen dieser ausführbaren Datei herunterzufahren.

Obwohl ein Prozess Id für eine einzelne Prozessressource auf dem System eindeutig ist, können mehrere Prozesse auf dem lokalen Computer die durch den processName Parameter angegebene Anwendung ausführen. Gibt daher höchstens einen Prozess zurück, gibt jedoch GetProcessesByName ein Array zurück, GetProcessById das alle zugeordneten Prozesse enthält. Wenn Sie den Prozess mithilfe von Standard-API-Aufrufen bearbeiten müssen, können Sie jeden dieser Prozesse nach dem Bezeichner abfragen. Sie können nicht allein über den Prozessnamen auf Prozessressourcen zugreifen, aber sobald Sie ein Array von Process Komponenten abgerufen haben, die den Prozessressourcen zugeordnet wurden, können Sie die Systemressourcen starten, beenden und anderweitig bearbeiten.

Sie können diese Überladung verwenden, um Prozesse sowohl auf dem lokalen Computer als auch auf einem Remotecomputer abzurufen. Verwenden Sie ".", um den lokalen Computer anzugeben. Es ist eine weitere Überladung vorhanden, die standardmäßig den lokalen Computer verwendet.

Sie können nur auf Prozesse auf Remotecomputern zugreifen, um Informationen wie z. B. Statistiken zu den Prozessen anzuzeigen. Sie können Prozesse auf Remotecomputern nicht schließen, beenden (mit Kill) oder starten.

Weitere Informationen

Gilt für:

GetProcessesByName(String)

Erstellt ein Array neuer Process-Komponenten und ordnet diese allen Prozessressourcen auf dem lokalen Computer zu, die den angegebenen Prozessnamen gemeinsam verwenden.

public:
 static cli::array <System::Diagnostics::Process ^> ^ GetProcessesByName(System::String ^ processName);
public static System.Diagnostics.Process[] GetProcessesByName (string? processName);
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.Process[] GetProcessesByName (string? processName);
public static System.Diagnostics.Process[] GetProcessesByName (string processName);
static member GetProcessesByName : string -> System.Diagnostics.Process[]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member GetProcessesByName : string -> System.Diagnostics.Process[]
Public Shared Function GetProcessesByName (processName As String) As Process()

Parameter

processName
String

Der angezeigte Name des Prozesses.

Gibt zurück

Ein Array vom Typ Process, das die Prozessressourcen darstellt, die die angegebene Anwendung oder Datei ausführen.

Attribute

Ausnahmen

Beim Zugriff auf die Leistungsindikator-APIs zum Abrufen von Prozessinformationen treten Probleme auf. Diese Ausnahme tritt nur unter Windows NT, Windows 2000 und Windows XP auf.

Beispiele

Im folgenden Beispiel werden Informationen zum aktuellen Prozess, prozesse, 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 abgerufen. Anschließend werden Informationen für die gleichen Prozesse auf einem Remotecomputer abgerufen.

#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

Hinweise

Verwenden Sie diese Methode, um ein Array neuer Process Komponenten zu erstellen und sie allen Prozessressourcen zuzuordnen, die dieselbe ausführbare Datei auf dem lokalen Computer ausführen. Die Prozessressourcen müssen bereits auf dem Computer vorhanden sein, da GetProcessesByName keine Systemressourcen erstellt, sondern mit anwendungsgenerierten Komponenten verknüpft Process werden. Ein processName kann für eine ausführbare Datei angegeben werden, die derzeit nicht auf dem lokalen Computer ausgeführt wird, sodass das von der Methode zurückgegebene Array leer sein kann.

Der Prozessname ist ein Anzeigename für den Prozess, z. B. Outlook, der die .exe-Erweiterung oder den Pfad nicht enthält. GetProcessesByName ist hilfreich, um alle Prozesse zu erhalten und zu bearbeiten, die derselben ausführbaren Datei zugeordnet sind. Sie können beispielsweise einen ausführbaren Dateinamen als processName Parameter übergeben, um alle ausgeführten Instanzen dieser ausführbaren Datei herunterzufahren.

Obwohl ein Prozess Id für eine einzelne Prozessressource auf dem System eindeutig ist, können mehrere Prozesse auf dem lokalen Computer die durch den processName Parameter angegebene Anwendung ausführen. Gibt daher höchstens einen Prozess zurück, gibt jedoch GetProcessesByName ein Array zurück, GetProcessById das alle zugeordneten Prozesse enthält. Wenn Sie den Prozess mithilfe von Standard-API-Aufrufen bearbeiten müssen, können Sie jeden dieser Prozesse nach dem Bezeichner abfragen. Sie können nicht allein über den Prozessnamen auf Prozessressourcen zugreifen, aber sobald Sie ein Array von Process Komponenten abgerufen haben, die den Prozessressourcen zugeordnet wurden, können Sie die Systemressourcen starten, beenden und anderweitig bearbeiten.

Weitere Informationen

Gilt für: