Process.GetProcesses Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Vytvoří pole nových Process komponent a přidruží je k existujícím prostředkům procesů.
Přetížení
GetProcesses() |
Vytvoří novou Process komponentu pro každý prostředek procesu v místním počítači. |
GetProcesses(String) |
Vytvoří novou Process komponentu pro každý prostředek procesu v zadaném počítači. |
GetProcesses()
Vytvoří novou Process komponentu pro každý prostředek procesu v místním počítači.
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()
Návraty
- Process[]
Pole typu Process , které představuje všechny procesní prostředky 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é na místním počítači, všechny instance Poznámkového bloku spuštěné na místním počítači a konkrétní proces v místním počítači. Potom načte informace pro stejné procesy na vzdáleném počítači.
#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
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 vygenerovaným Process aplikacím. Protož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í metody GetProcessById nebo GetProcessesByName metody. GetProcessById vytvoří komponentu Process přidruženou k procesu zjištěnému v systému identifikátorem procesu, který předáváte metodě. GetProcessesByName vytvoří pole Process komponent, jejichž přidružené procesní prostředky sdílejí spustitelný soubor, který předáváte metodě.
Poznámka
V rámci stejné instance procesu hostitele služby (svchost.exe) je možné načíst více služeb Systému Windows. GetProcesses tyto jednotlivé služby neidentifikuje; viz .GetServices
Viz také
Platí pro
GetProcesses(String)
Vytvoří novou Process komponentu pro každý prostředek procesu v zadaném počítači.
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()
Parametry
- machineName
- String
Počítač, ze kterého chcete přečíst seznam procesů.
Návraty
- Process[]
Pole typu Process , které představuje všechny procesní prostředky spuštěné v zadaném počítači.
- Atributy
Výjimky
Syntaxe parametru machineName
je neplatná. Může mít délku nuly (0).
Parametr machineName
je null
.
Platforma operačního systému tuto operaci nepodporuje na vzdálených počítačích.
Při přístupu k rozhraním API čítače výkonu používaného k získání informací o procesu dochází k problémům. Tato výjimka je specifická pro systém 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é na místním počítači, všechny instance Poznámkového bloku spuštěné na místním počítači a konkrétní proces v místním počítači. Potom načte informace pro stejné procesy na vzdáleném počítači.
#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
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 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 vygenerovaným Process aplikacím. Protož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í metody GetProcessById nebo GetProcessesByName metody. GetProcessById vytvoří komponentu Process přidruženou k procesu zjištěnému v systému identifikátorem procesu, který předáváte metodě. GetProcessesByName vytvoří pole Process komponent, jejichž přidružené procesní prostředky sdílejí spustitelný soubor, který předáváte metodě.
Toto přetížení GetProcesses metody se obvykle používá k načtení seznamu procesních prostředků spuštěných na vzdáleném počítači v síti, ale můžete určit místní počítač předáním "".
Poznámka
V rámci stejné instance procesu hostitele služby (svchost.exe) je možné načíst více služeb Systému Windows. GetProcesses tyto jednotlivé služby neidentifikuje; viz .GetServices