Process.GetProcesses Process.GetProcesses Process.GetProcesses Process.GetProcesses Method

Définition

Crée un tableau de nouveaux composants Process et les associe à des ressources de processus existantes.Creates an array of new Process components and associates them with existing process resources.

Surcharges

GetProcesses(String) GetProcesses(String) GetProcesses(String) GetProcesses(String)

Crée un composant Process pour chaque ressource de processus sur l'ordinateur spécifié.Creates a new Process component for each process resource on the specified computer.

GetProcesses() GetProcesses() GetProcesses() GetProcesses()

Crée un composant Process pour chaque ressource de processus sur l'ordinateur local.Creates a new Process component for each process resource on the local computer.

GetProcesses(String) GetProcesses(String) GetProcesses(String) GetProcesses(String)

Crée un composant Process pour chaque ressource de processus sur l'ordinateur spécifié.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()

Paramètres

machineName
String String String String

Ordinateur à partir duquel lire la liste de processus.The computer from which to read the list of processes.

Retours

Tableau de type Process représentant toutes les ressources de processus exécutées sur l'ordinateur spécifié.An array of type Process that represents all the process resources running on the specified computer.

Exceptions

La syntaxe du paramètre machineName n’est pas valide.The machineName parameter syntax is invalid. Sa longueur est peut-être égale à zéro (0).It might have length zero (0).

Le paramètre machineName a la valeur null.The machineName parameter is null.

La plateforme du système d’exploitation ne prend pas en charge cette opération sur les ordinateurs distants.The operating system platform does not support this operation on remote computers.

L’accès à l’API du compteur de performance pour obtenir des informations sur les processus présente des problèmes.There are problems accessing the performance counter API's used to get process information. Cette exception est propre à Windows NT, Windows 2000 et Windows XP.This exception is specific to Windows NT, Windows 2000, and Windows XP.

Un problème s’est produit pendant l’accès à l’API système sous-jacente.A problem occurred accessing an underlying system API.

Exemples

L’exemple suivant récupère les informations du processus en cours, les processus en cours d’exécution sur l’ordinateur local, toutes les instances du bloc-notes en cours d’exécution sur l’ordinateur local et un processus spécifique sur l’ordinateur local.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. Il récupère ensuite des informations pour les mêmes processus sur un ordinateur distant.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
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 'BindToRunningProcesses

        Shared Sub Main()
            Dim myProcess As New MyProcess()
            myProcess.BindToRunningProcesses()
        End Sub 'Main 

    End Class 'MyProcess

End Namespace 'MyProcessSample

Remarques

Utilisez cette méthode pour créer un tableau de nouveaux Process composants et les associer à toutes les ressources de processus sur l’ordinateur spécifié (généralement à distance).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. Les ressources de processus doivent déjà exister sur l’ordinateur local, car GetProcesses ne crée pas de ressources système, mais associe plutôt les ressources générés par l’application Process composants.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. Étant donné que le système d’exploitation lui-même est en cours d’exécution des processus d’arrière-plan, ce tableau n’est jamais vide.Because the operating system itself is running background processes, this array is never empty.

Si vous ne souhaitez pas récupérer tous les processus en cours d’exécution sur l’ordinateur, vous pouvez restreindre leur nombre à l’aide de la GetProcessById ou GetProcessesByName (méthode).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 Crée un Process composant qui est associé au processus identifié sur le système par l’identificateur de processus que vous passez à la méthode.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 Crée un tableau de Process composants dont les ressources des processus associés partagent le fichier exécutable que vous passez à la méthode.GetProcessesByName creates an array of Process components whose associated process resources share the executable file you pass to the method.

Cette surcharge de la GetProcesses méthode est généralement utilisée pour récupérer la liste des ressources de processus en cours d’exécution sur un ordinateur distant sur le réseau, mais vous pouvez spécifier l’ordinateur local en passant «. ».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 ".".

Notes

Plusieurs services Windows peuvent être chargées dans la même instance du processus hôte de Service (svchost.exe).Multiple Windows services can be loaded within the same instance of the Service Host process (svchost.exe). GetProcesses n’identifie pas ces services individuels ; Pour ce faire, consultez GetServices.GetProcesses does not identify those individual services; for that, see GetServices.

Sécurité

LinkDemand
pour la confiance totale pour l’appelant immédiat.for full trust for the immediate caller. Ce membre ne peut pas être utilisé par du code d'un niveau de confiance partiel.This member cannot be used by partially trusted code.

Voir aussi

GetProcesses() GetProcesses() GetProcesses() GetProcesses()

Crée un composant Process pour chaque ressource de processus sur l'ordinateur local.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()

Retours

Tableau de type Process représentant toutes les ressources de processus exécutées sur l'ordinateur local.An array of type Process that represents all the process resources running on the local computer.

Exemples

L’exemple suivant récupère les informations du processus en cours, les processus en cours d’exécution sur l’ordinateur local, toutes les instances du bloc-notes en cours d’exécution sur l’ordinateur local et un processus spécifique sur l’ordinateur local.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. Il récupère ensuite des informations pour les mêmes processus sur un ordinateur distant.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
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 'BindToRunningProcesses

        Shared Sub Main()
            Dim myProcess As New MyProcess()
            myProcess.BindToRunningProcesses()
        End Sub 'Main 

    End Class 'MyProcess

End Namespace 'MyProcessSample

Remarques

Utilisez cette méthode pour créer un tableau de nouveaux Process composants et les associer à toutes les ressources de processus sur l’ordinateur local.Use this method to create an array of new Process components and associate them with all the process resources on the local computer. Les ressources de processus doivent déjà exister sur l’ordinateur local, car GetProcesses ne crée pas de ressources système, mais associe plutôt les ressources générés par l’application Process composants.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. Étant donné que le système d’exploitation lui-même est en cours d’exécution des processus d’arrière-plan, ce tableau n’est jamais vide.Because the operating system itself is running background processes, this array is never empty.

Si vous ne souhaitez pas récupérer tous les processus en cours d’exécution sur l’ordinateur, vous pouvez restreindre leur nombre à l’aide de la GetProcessById ou GetProcessesByName (méthode).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 Crée un Process composant qui est associé au processus identifié sur le système par l’identificateur de processus que vous passez à la méthode.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 Crée un tableau de Process composants dont les ressources des processus associés partagent le fichier exécutable que vous passez à la méthode.GetProcessesByName creates an array of Process components whose associated process resources share the executable file you pass to the method.

Notes

Plusieurs services Windows peuvent être chargées dans la même instance du processus hôte de Service (svchost.exe).Multiple Windows services can be loaded within the same instance of the Service Host process (svchost.exe). GetProcesses n’identifie pas ces services individuels ; Pour ce faire, consultez GetServices.GetProcesses does not identify those individual services; for that, see GetServices.

Sécurité

LinkDemand
pour la confiance totale pour l’appelant immédiat.for full trust for the immediate caller. Ce membre ne peut pas être utilisé par du code d'un niveau de confiance partiel.This member cannot be used by partially trusted code.

Voir aussi

S’applique à