Process.GetProcesses Metoda

Definice

Vytvoří pole nových Process komponent a přidruží je k existujícím prostředkům procesu.

Přetížení

Name Description
GetProcesses()

Vytvoří novou komponentu Process pro každý prostředek procesu v místním počítači.

GetProcesses(String)

Vytvoří novou komponentu Process pro každý prostředek procesu v zadaném počítači.

GetProcesses()

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

Vytvoří novou komponentu Process pro každý prostředek procesu v místním počítači.

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

Návraty

Pole typu Process , které představuje všechny prostředky procesu spuštěné v místním počítači.

Atributy

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 pole nových Process komponent a přidružte je ke všem prostředkům procesu v místním počítači. Prostředky procesu již musí existovat v místním počítači, protože GetProcesses nevytvoří systémové prostředky, ale spíše přidruží prostředky k komponentám generovaným Process aplikacím. Vzhledem k tomu, že samotný operační systém spouští procesy na pozadí, toto pole není nikdy prázdné.

Pokud nechcete načíst všechny procesy spuštěné v počítači, můžete jejich počet omezit pomocí GetProcessById metody nebo GetProcessesByName metody. GetProcessById vytvoří komponentu Process přidruženou k procesu identifikovanému v systému identifikátorem procesu, který předáte metodě. GetProcessesByName vytvoří pole Process komponent, jejichž přidružené prostředky procesu sdílejí spustitelný soubor, který předáte metodě.

Note

V rámci stejné instance procesu hostitele služby (svchost.exe) lze načíst více Windows služeb. GetProcesses tyto jednotlivé služby neidentifikuje; viz .GetServices

Viz také

Platí pro

GetProcesses(String)

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

Vytvoří novou komponentu Process pro každý prostředek procesu v zadaném počítači.

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

Parametry

machineName
String

Počítač, ze kterého se má přečíst seznam procesů.

Návraty

Pole typu Process , které představuje všechny procesní prostředky spuštěné v zadaném počítači.

Atributy

Výjimky

machineName Syntaxe parametru je neplatná. Může mít délku nula (0).

Parametr machineName je null.

Platforma operačního systému tuto operaci na vzdálených počítačích nepodporuje.

Při přístupu k rozhraním API čítačů výkonu, která se používají k získání informací o procesu, dochází k problémům. Tato výjimka je specifická pro Windows NT, Windows 2000 a Windows XP.

Při přístupu k základnímu systémovému rozhraní API došlo k problému.

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

Tato metoda slouží k vytvoření pole nových Process komponent a jejich přidružení ke všem prostředkům procesu v zadaném (obvykle vzdáleném) počítači. Prostředky procesu již musí existovat v místním počítači, protože GetProcesses nevytvoří systémové prostředky, ale spíše přidruží prostředky k komponentám generovaným Process aplikacím. Vzhledem k tomu, že samotný operační systém spouští procesy na pozadí, toto pole není nikdy prázdné.

Pokud nechcete načíst všechny procesy spuštěné v počítači, můžete jejich počet omezit pomocí GetProcessById metody nebo GetProcessesByName metody. GetProcessById vytvoří komponentu Process přidruženou k procesu identifikovanému v systému identifikátorem procesu, který předáte metodě. GetProcessesByName vytvoří pole Process komponent, jejichž přidružené prostředky procesu sdílejí spustitelný soubor, který předáte metodě.

Toto přetížení GetProcesses metody se obvykle používá k načtení seznamu procesních prostředků spuštěných ve vzdáleném počítači v síti, ale můžete určit místní počítač předáním ".".

Note

V rámci stejné instance procesu hostitele služby (svchost.exe) lze načíst více Windows služeb. GetProcesses tyto jednotlivé služby neidentifikuje; viz .GetServices

Viz také

Platí pro