Process.GetProcesses Metoda

Definicja

Tworzy tablicę nowych Process składników i kojarzy je z istniejącymi zasobami procesów.Creates an array of new Process components and associates them with existing process resources.

Przeciążenia

GetProcesses()

Tworzy nowy Process składnik dla każdego zasobu procesu na komputerze lokalnym.Creates a new Process component for each process resource on the local computer.

GetProcesses(String)

Tworzy nowy Process składnik dla każdego zasobu procesu na określonym komputerze.Creates a new Process component for each process resource on the specified computer.

GetProcesses()

Tworzy nowy Process składnik dla każdego zasobu procesu na komputerze lokalnym.Creates a new Process component for each process resource on the local computer.

public:
 static cli::array <System::Diagnostics::Process ^> ^ GetProcesses();
public static System.Diagnostics.Process[] GetProcesses ();
static member GetProcesses : unit -> System.Diagnostics.Process[]
Public Shared Function GetProcesses () As Process()

Zwraca

Process[]

Tablica typu Process , która reprezentuje wszystkie zasoby procesu uruchomione na komputerze lokalnym.An array of type Process that represents all the process resources running on the local computer.

Przykłady

Poniższy przykład pobiera informacje o bieżącym procesie, procesach uruchomionych na komputerze lokalnym, wszystkich wystąpieniach programu Notepad uruchomionych na komputerze lokalnym i określonym procesie na komputerze lokalnym.The following example retrieves information of the current process, processes running on the local computer, all instances of Notepad running on the local computer, and a specific process on the local computer. Następnie pobiera informacje dotyczące tych samych procesów na komputerze zdalnym.It then retrieves information for the same processes on a remote computer.

#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

Ta metoda służy do tworzenia tablicy nowych Process składników i kojarzenia ich ze wszystkimi zasobami procesów na komputerze lokalnym.Use this method to create an array of new Process components and associate them with all the process resources on the local computer. Zasoby procesu muszą już istnieć na komputerze lokalnym, ponieważ nie GetProcesses tworzy zasobów systemowych, ale raczej kojarzy zasoby z składnikami wygenerowanymi przez aplikację Process .The process resources must already exist on the local computer, because GetProcesses does not create system resources but rather associates resources with application-generated Process components. Ponieważ sam system operacyjny ma uruchomione procesy w tle, ta tablica nie jest pusta.Because the operating system itself is running background processes, this array is never empty.

Jeśli nie chcesz pobierać wszystkich procesów uruchomionych na komputerze, możesz ograniczyć ich liczbę przy użyciu GetProcessById GetProcessesByName metody lub.If you do not want to retrieve all the processes running on the computer, you can restrict their number by using the GetProcessById or GetProcessesByName method. GetProcessById tworzy Process składnik skojarzony z procesem zidentyfikowanym w systemie przez identyfikator procesu, który został przekazany do metody.GetProcessById creates a Process component that is associated with the process identified on the system by the process identifier that you pass to the method. GetProcessesByName Tworzy tablicę Process składników, której skojarzone zasoby procesu współużytkują plik wykonywalny przekazywany do metody.GetProcessesByName creates an array of Process components whose associated process resources share the executable file you pass to the method.

Uwaga

Można załadować wiele usług systemu Windows w ramach tego samego wystąpienia procesu hosta usługi (svchost.exe).Multiple Windows services can be loaded within the same instance of the Service Host process (svchost.exe). Proces getprocesss nie identyfikuje tych pojedynczych usług; w tym celu zobacz GetServices .GetProcesses does not identify those individual services; for that, see GetServices.

Zobacz też

Dotyczy

GetProcesses(String)

Tworzy nowy Process składnik dla każdego zasobu procesu na określonym komputerze.Creates a new Process component for each process resource on the specified computer.

public:
 static cli::array <System::Diagnostics::Process ^> ^ GetProcesses(System::String ^ machineName);
public static System.Diagnostics.Process[] GetProcesses (string machineName);
static member GetProcesses : string -> System.Diagnostics.Process[]
Public Shared Function GetProcesses (machineName As String) As Process()

Parametry

machineName
String

Komputer, z którego ma zostać odczytana lista procesów.The computer from which to read the list of processes.

Zwraca

Process[]

Tablica typu Process , która reprezentuje wszystkie zasoby procesu uruchomione na określonym komputerze.An array of type Process that represents all the process resources running on the specified computer.

Wyjątki

machineNameSkładnia parametru jest nieprawidłowa.The machineName parameter syntax is invalid. Może mieć długość zero (0).It might have length zero (0).

machineNameParametr ma wartość null .The machineName parameter is null.

Platforma systemu operacyjnego nie obsługuje tej operacji na komputerach zdalnych.The operating system platform does not support this operation on remote computers.

Występują problemy z dostępem do interfejsów API liczników wydajności używanych do uzyskiwania informacji o procesie.There are problems accessing the performance counter APIs used to get process information. Ten wyjątek dotyczy systemów Windows NT, Windows 2000 i Windows XP.This exception is specific to Windows NT, Windows 2000, and Windows XP.

Wystąpił problem podczas uzyskiwania dostępu do podstawowego interfejsu API systemu.A problem occurred accessing an underlying system API.

Przykłady

Poniższy przykład pobiera informacje o bieżącym procesie, procesach uruchomionych na komputerze lokalnym, wszystkich wystąpieniach programu Notepad uruchomionych na komputerze lokalnym i określonym procesie na komputerze lokalnym.The following example retrieves information of the current process, processes running on the local computer, all instances of Notepad running on the local computer, and a specific process on the local computer. Następnie pobiera informacje dotyczące tych samych procesów na komputerze zdalnym.It then retrieves information for the same processes on a remote computer.

#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

Ta metoda służy do tworzenia tablicy nowych Process składników i kojarzenia ich ze wszystkimi zasobami procesów na określonym (zazwyczaj zdalnym) komputerze.Use this method to create an array of new Process components and associate them with all the process resources on the specified (usually remote) computer. Zasoby procesu muszą już istnieć na komputerze lokalnym, ponieważ nie GetProcesses tworzy zasobów systemowych, ale raczej kojarzy zasoby z składnikami wygenerowanymi przez aplikację Process .The process resources must already exist on the local computer, because GetProcesses does not create system resources but rather associates resources with application-generated Process components. Ponieważ sam system operacyjny ma uruchomione procesy w tle, ta tablica nie jest pusta.Because the operating system itself is running background processes, this array is never empty.

Jeśli nie chcesz pobierać wszystkich procesów uruchomionych na komputerze, możesz ograniczyć ich liczbę przy użyciu GetProcessById GetProcessesByName metody lub.If you do not want to retrieve all the processes running on the computer, you can restrict their number by using the GetProcessById or GetProcessesByName method. GetProcessById tworzy Process składnik skojarzony z procesem zidentyfikowanym w systemie przez identyfikator procesu, który został przekazany do metody.GetProcessById creates a Process component that is associated with the process identified on the system by the process identifier that you pass to the method. GetProcessesByName Tworzy tablicę Process składników, której skojarzone zasoby procesu współużytkują plik wykonywalny przekazywany do metody.GetProcessesByName creates an array of Process components whose associated process resources share the executable file you pass to the method.

To Przeciążenie GetProcesses metody jest zwykle używane do pobierania listy zasobów procesów uruchomionych na komputerze zdalnym w sieci, ale można określić komputer lokalny, przekazując ".".This overload of the GetProcesses method is generally used to retrieve the list of process resources running on a remote computer on the network, but you can specify the local computer by passing ".".

Uwaga

Można załadować wiele usług systemu Windows w ramach tego samego wystąpienia procesu hosta usługi (svchost.exe).Multiple Windows services can be loaded within the same instance of the Service Host process (svchost.exe). Proces getprocesss nie identyfikuje tych pojedynczych usług; w tym celu zobacz GetServices .GetProcesses does not identify those individual services; for that, see GetServices.

Zobacz też

Dotyczy