Process.GetProcesses Metoda

Definicja

Tworzy tablicę nowych Process składników i kojarzy je z istniejącymi zasobami procesu.

Przeciążenia

GetProcesses()

Tworzy nowy Process składnik dla każdego zasobu procesu na komputerze lokalnym.

GetProcesses(String)

Tworzy nowy Process składnik dla każdego zasobu procesu na określonym komputerze.

GetProcesses()

Źródło:
Process.cs
Źródło:
Process.cs
Źródło:
Process.cs

Tworzy nowy Process składnik dla każdego zasobu procesu na komputerze lokalnym.

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()

Zwraca

Tablica typu Process reprezentująca wszystkie zasoby procesu uruchomione na komputerze lokalnym.

Atrybuty

Przykłady

Poniższy przykład pobiera informacje o bieżącym procesie, procesy uruchomione na komputerze lokalnym, wszystkie wystąpienia Notatnika uruchomione na komputerze lokalnym i określony proces na komputerze lokalnym. Następnie pobiera informacje o tych samych procesach na komputerze zdalnym.

#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

Uwagi

Użyj tej metody, aby utworzyć tablicę nowych Process składników i skojarzyć je ze wszystkimi zasobami procesu na komputerze lokalnym. Zasoby procesu muszą już istnieć na komputerze lokalnym, ponieważ GetProcesses nie tworzy zasobów systemowych, ale raczej kojarzy zasoby ze składnikami wygenerowanymi Process przez aplikację. Ponieważ sam system operacyjny uruchamia procesy w tle, ta tablica nigdy nie jest pusta.

Jeśli nie chcesz pobierać wszystkich procesów uruchomionych na komputerze, możesz ograniczyć ich liczbę przy użyciu GetProcessById metody or GetProcessesByName . GetProcessByIdProcess tworzy składnik skojarzony z procesem zidentyfikowanym w systemie przez identyfikator procesu przekazywany do metody. GetProcessesByName Tworzy tablicę składników Process , których skojarzone zasoby procesu współużytkować plik wykonywalny przekazywany do metody.

Uwaga

Wiele usług systemu Windows można załadować w tym samym wystąpieniu procesu hosta usługi (svchost.exe). GetProcesses nie identyfikuje tych indywidualnych usług; w tym celu zobacz GetServices.

Zobacz też

Dotyczy

GetProcesses(String)

Źródło:
Process.cs
Źródło:
Process.cs
Źródło:
Process.cs

Tworzy nowy Process składnik dla każdego zasobu procesu na określonym komputerze.

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

Komputer, z którego ma być odczytywana lista procesów.

Zwraca

Tablica typu Process reprezentująca wszystkie zasoby procesu uruchomione na określonym komputerze.

Atrybuty

Wyjątki

Składnia parametru jest nieprawidłowa machineName . Może mieć długość zero (0).

Parametr machineName to null.

Platforma systemu operacyjnego nie obsługuje tej operacji na komputerach zdalnych.

Występują problemy z uzyskiwaniem dostępu do interfejsów API licznika wydajności używanych do uzyskiwania informacji o procesie. Ten wyjątek jest specyficzny dla systemów Windows NT, Windows 2000 i Windows XP.

Wystąpił problem podczas uzyskiwania dostępu do bazowego interfejsu API systemu.

Przykłady

Poniższy przykład pobiera informacje o bieżącym procesie, procesy uruchomione na komputerze lokalnym, wszystkie wystąpienia Notatnika uruchomione na komputerze lokalnym i określony proces na komputerze lokalnym. Następnie pobiera informacje o tych samych procesach na komputerze zdalnym.

#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

Uwagi

Użyj tej metody, aby utworzyć tablicę nowych Process składników i skojarzyć je ze wszystkimi zasobami procesu na określonym (zwykle zdalnym) komputerze. Zasoby procesu muszą już istnieć na komputerze lokalnym, ponieważ GetProcesses nie tworzy zasobów systemowych, ale raczej kojarzy zasoby ze składnikami wygenerowanymi Process przez aplikację. Ponieważ sam system operacyjny uruchamia procesy w tle, ta tablica nigdy nie jest pusta.

Jeśli nie chcesz pobierać wszystkich procesów uruchomionych na komputerze, możesz ograniczyć ich liczbę przy użyciu GetProcessById metody or GetProcessesByName . GetProcessByIdProcess tworzy składnik skojarzony z procesem zidentyfikowanym w systemie przez identyfikator procesu przekazywany do metody. GetProcessesByName Tworzy tablicę składników Process , których skojarzone zasoby procesu współużytkować plik wykonywalny przekazywany do metody.

To przeciążenie GetProcesses metody jest zwykle używane do pobierania listy zasobów procesu uruchomionych na komputerze zdalnym w sieci, ale można określić komputer lokalny, przekazując ".".

Uwaga

Wiele usług systemu Windows można załadować w tym samym wystąpieniu procesu hosta usługi (svchost.exe). GetProcesses nie identyfikuje tych indywidualnych usług; w tym celu zobacz GetServices.

Zobacz też

Dotyczy