Process.GetProcesses Methode

Definition

Erstellt ein Array neuer Process-Komponenten und ordnet diese den vorhandenen Prozessressourcen zu.

Überlädt

GetProcesses()

Erstellt eine neue Process-Komponente für jede Prozessressource auf dem lokalen Computer.

GetProcesses(String)

Erstellt eine neue Process-Komponente für jede Prozessressource auf dem lokalen Computer.

GetProcesses()

Erstellt eine neue Process-Komponente für jede Prozessressource auf dem lokalen Computer.

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

Gibt zurück

Process[]

Ein Array vom Typ Process, das alle auf dem lokalen Computer ausgeführten Prozessressourcen darstellt.

Attribute

Beispiele

Im folgenden Beispiel werden Informationen des aktuellen Prozesses abgerufen, Prozesse, die auf dem lokalen Computer ausgeführt werden, alle Instanzen von Notepad, die auf dem lokalen Computer ausgeführt werden, und einen bestimmten Prozess auf dem lokalen Computer. Anschließend werden Informationen für dieselben 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 auf dem lokalen Computer zuzuordnen. Die Prozessressourcen müssen bereits auf dem lokalen Computer vorhanden sein, da GetProcesses keine Systemressourcen erstellt werden, sondern Ressourcen mit anwendungsgenerierten Process Komponenten verknüpft werden. Da das Betriebssystem selbst Hintergrundprozesse ausführt, ist dieses Array nie leer.

Wenn Sie nicht alle Prozesse abrufen möchten, die auf dem Computer ausgeführt werden, können Sie ihre Nummer mithilfe der GetProcessById Methode einschränken GetProcessesByName . GetProcessById erstellt eine Process Komponente, die dem im System identifizierten Prozess durch die Prozessbezeichner, die Sie an die Methode übergeben, zugeordnet ist. GetProcessesByName erstellt ein Array von Process Komponenten, deren zugeordnete Prozessressourcen die ausführbare Datei freigeben, die Sie an die Methode übergeben.

Hinweis

Mehrere Windows-Dienste können innerhalb derselben Instanz des Diensthostvorgangs (svchost.exe) geladen werden. GetProcesses identifiziert diese einzelnen Dienste nicht; dazu finden Sie unter GetServices.

Siehe auch

Gilt für

GetProcesses(String)

Erstellt eine neue Process-Komponente für jede Prozessressource auf dem lokalen Computer.

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

Parameter

machineName
String

Der Computer, von dem die Liste der Prozesse gelesen werden soll.

Gibt zurück

Process[]

Ein Array vom Typ Process, das alle auf dem angegebenen Computer ausgeführten Prozessressourcen darstellt.

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.

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 des aktuellen Prozesses abgerufen, Prozesse, die auf dem lokalen Computer ausgeführt werden, alle Instanzen von Notepad, die auf dem lokalen Computer ausgeführt werden, und einen bestimmten Prozess auf dem lokalen Computer. Anschließend werden Informationen für dieselben 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 auf dem angegebenen (normalerweise Remotecomputer) zuzuordnen. Die Prozessressourcen müssen bereits auf dem lokalen Computer vorhanden sein, da GetProcesses keine Systemressourcen erstellt werden, sondern Ressourcen mit anwendungsgenerierten Process Komponenten verknüpft werden. Da das Betriebssystem selbst Hintergrundprozesse ausführt, ist dieses Array nie leer.

Wenn Sie nicht alle Prozesse abrufen möchten, die auf dem Computer ausgeführt werden, können Sie ihre Nummer mithilfe der GetProcessById Methode einschränken GetProcessesByName . GetProcessById erstellt eine Process Komponente, die dem im System identifizierten Prozess durch die Prozessbezeichner, die Sie an die Methode übergeben, zugeordnet ist. GetProcessesByName erstellt ein Array von Process Komponenten, deren zugeordnete Prozessressourcen die ausführbare Datei freigeben, die Sie an die Methode übergeben.

Diese Überladung der Methode wird im Allgemeinen verwendet, um die Liste der GetProcesses Prozessressourcen abzurufen, die auf einem Remotecomputer im Netzwerk ausgeführt werden, sie können jedoch den lokalen Computer angeben, indem Sie ".".

Hinweis

Mehrere Windows-Dienste können innerhalb derselben Instanz des Diensthostvorgangs (svchost.exe) geladen werden. GetProcesses identifiziert diese einzelnen Dienste nicht; dazu finden Sie unter GetServices.

Siehe auch

Gilt für