Process.GetProcessesByName Méthode

Définition

Crée un tableau de nouveaux Process composants et les associe aux ressources de processus existantes qui partagent tous le nom de processus spécifié.

Surcharges

Nom Description
GetProcessesByName(String, String)

Crée un tableau de nouveaux composants Process et les associe à toutes les ressources de processus sur un ordinateur distant qui partagent le nom de processus spécifié.

GetProcessesByName(String)

Crée un tableau de nouveaux composants Process et les associe à toutes les ressources de processus sur l’ordinateur local qui partagent le nom de processus spécifié.

GetProcessesByName(String, String)

Crée un tableau de nouveaux composants Process et les associe à toutes les ressources de processus sur un ordinateur distant qui partagent le nom de processus spécifié.

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

Paramètres

processName
String

Nom convivial du processus.

machineName
String

Nom d’un ordinateur sur le réseau.

Retours

Tableau de type Process qui représente les ressources de processus exécutant l’application ou le fichier spécifiés.

Exceptions

La syntaxe des machineName paramètres n’est pas valide. Il peut avoir la longueur zéro (0).

Le machineName paramètre est null.

La plateforme du système d’exploitation ne prend pas en charge cette opération sur les ordinateurs distants.

Échec de la tentative de connexion machineName .

-ou-

Il existe des problèmes d’accès aux API de compteur de performances utilisées pour obtenir des informations sur le processus. Cette exception est spécifique à Windows NT, Windows 2000 et Windows XP.

Un problème s’est produit lors de l’accès à une API système sous-jacente.

Exemples

L’exemple suivant récupère les informations du processus actuel, les processus s’exécutant sur l’ordinateur local, toutes les instances du Bloc-notes s’exécutant sur l’ordinateur local et un processus spécifique sur l’ordinateur local. Il récupère ensuite des informations pour les mêmes processus sur un ordinateur distant.

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

Remarques

Utilisez cette méthode pour créer un tableau de nouveaux Process composants et les associer à toutes les ressources de processus qui exécutent le même fichier exécutable sur l’ordinateur spécifié. Les ressources de processus doivent déjà exister sur l’ordinateur, car GetProcessesByName elles ne créent pas de ressources système, mais les associent à des composants générés par Process l’application. Vous pouvez spécifier un processName fichier exécutable qui n’est pas en cours d’exécution sur l’ordinateur local, de sorte que le tableau retourné par la méthode peut être vide.

Le nom du processus est un nom convivial pour le processus, tel que Outlook, qui n’inclut pas l’extension .exe ou le chemin d’accès. GetProcessesByName est utile pour obtenir et manipuler tous les processus associés au même fichier exécutable. Par exemple, vous pouvez transmettre un nom de fichier exécutable en tant que processName paramètre, afin d’arrêter toutes les instances en cours d’exécution de ce fichier exécutable.

Bien qu’un processus Id soit unique pour une ressource de processus sur le système, plusieurs processus sur l’ordinateur local peuvent exécuter l’application spécifiée par le processName paramètre. Par conséquent, GetProcessById retourne un processus au plus, mais GetProcessesByName retourne un tableau contenant tous les processus associés. Si vous devez manipuler le processus à l’aide d’appels d’API standard, vous pouvez interroger chacun de ces processus à son tour pour son identificateur. Vous ne pouvez pas accéder aux ressources de processus uniquement par le biais du nom du processus, mais, une fois que vous avez récupéré un tableau de Process composants qui ont été associés aux ressources de processus, vous pouvez démarrer, terminer et manipuler les ressources système.

Vous pouvez utiliser cette surcharge pour obtenir des processus sur l’ordinateur local ainsi que sur un ordinateur distant. Utilisez « ». Pour spécifier l’ordinateur local. Une autre surcharge existe qui utilise l’ordinateur local par défaut.

Vous pouvez accéder aux processus sur des ordinateurs distants uniquement pour afficher des informations, telles que des statistiques, sur les processus. Vous ne pouvez pas fermer, terminer (à l’aide Kill) ou démarrer des processus sur des ordinateurs distants.

Voir aussi

S’applique à

GetProcessesByName(String)

Crée un tableau de nouveaux composants Process et les associe à toutes les ressources de processus sur l’ordinateur local qui partagent le nom de processus spécifié.

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

Paramètres

processName
String

Nom convivial du processus.

Retours

Tableau de type Process qui représente les ressources de processus exécutant l’application ou le fichier spécifiés.

Exceptions

Il existe des problèmes d’accès aux API de compteur de performances utilisées pour obtenir des informations sur le processus. Cette exception est spécifique à Windows NT, Windows 2000 et Windows XP.

Exemples

L’exemple suivant récupère les informations du processus actuel, les processus s’exécutant sur l’ordinateur local, toutes les instances du Bloc-notes s’exécutant sur l’ordinateur local et un processus spécifique sur l’ordinateur local. Il récupère ensuite des informations pour les mêmes processus sur un ordinateur distant.

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

Remarques

Utilisez cette méthode pour créer un tableau de nouveaux Process composants et les associer à toutes les ressources de processus qui exécutent le même fichier exécutable sur l’ordinateur local. Les ressources de processus doivent déjà exister sur l’ordinateur, car GetProcessesByName elles ne créent pas de ressources système, mais les associent à des composants générés par Process l’application. Vous pouvez spécifier un processName fichier exécutable qui n’est pas en cours d’exécution sur l’ordinateur local, de sorte que le tableau retourné par la méthode peut être vide.

Le nom du processus est un nom convivial pour le processus, tel que Outlook, qui n’inclut pas l’extension .exe ou le chemin d’accès. GetProcessesByName est utile pour obtenir et manipuler tous les processus associés au même fichier exécutable. Par exemple, vous pouvez transmettre un nom de fichier exécutable en tant que processName paramètre, afin d’arrêter toutes les instances en cours d’exécution de ce fichier exécutable.

Bien qu’un processus Id soit unique pour une ressource de processus sur le système, plusieurs processus sur l’ordinateur local peuvent exécuter l’application spécifiée par le processName paramètre. Par conséquent, GetProcessById retourne un processus au plus, mais GetProcessesByName retourne un tableau contenant tous les processus associés. Si vous devez manipuler le processus à l’aide d’appels d’API standard, vous pouvez interroger chacun de ces processus à son tour pour son identificateur. Vous ne pouvez pas accéder aux ressources de processus uniquement par le biais du nom du processus, mais, une fois que vous avez récupéré un tableau de Process composants qui ont été associés aux ressources de processus, vous pouvez démarrer, terminer et manipuler les ressources système.

Voir aussi

S’applique à