Process.GetProcessesByName Metodo

Definizione

Crea una matrice di nuovi Process componenti e le associa alle risorse di processo esistenti che condividono il nome del processo specificato.

Overload

Nome Descrizione
GetProcessesByName(String, String)

Crea una matrice di nuovi componenti Process e li associa a tutte le risorse di processo in un computer remoto che condividono il nome del processo specificato.

GetProcessesByName(String)

Crea una matrice di nuovi componenti Process e li associa a tutte le risorse di processo nel computer locale che condividono il nome del processo specificato.

GetProcessesByName(String, String)

Crea una matrice di nuovi componenti Process e li associa a tutte le risorse di processo in un computer remoto che condividono il nome del processo specificato.

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

Parametri

processName
String

Nome descrittivo del processo.

machineName
String

Nome di un computer in rete.

Valori restituiti

Matrice di tipo Process che rappresenta le risorse di processo che eseguono l'applicazione o il file specificato.

Eccezioni

La sintassi del machineName parametro non è valida. Potrebbe avere lunghezza zero (0).

Il machineName parametro è null.

La piattaforma del sistema operativo non supporta questa operazione nei computer remoti.

Il tentativo di connessione a machineName non è riuscito.

oppure

Esistono problemi durante l'accesso alle API del contatore delle prestazioni usate per ottenere informazioni sul processo. Questa eccezione è specifica per Windows NT, Windows 2000 e Windows XP.

Si è verificato un problema durante l'accesso a un'API di sistema sottostante.

Esempio

Nell'esempio seguente vengono recuperate le informazioni del processo corrente, i processi in esecuzione nel computer locale, tutte le istanze del Blocco note in esecuzione nel computer locale e un processo specifico nel computer locale. Recupera quindi le informazioni per gli stessi processi in un computer remoto.

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

Commenti

Utilizzare questo metodo per creare una matrice di nuovi Process componenti e associarli a tutte le risorse di processo che eseguono lo stesso file eseguibile nel computer specificato. Le risorse di processo devono esistere già nel computer, perché GetProcessesByName non crea risorse di sistema ma le associa ai componenti generati dall'applicazione Process . È processName possibile specificare un oggetto per un file eseguibile che non è attualmente in esecuzione nel computer locale, quindi la matrice restituita dal metodo può essere vuota.

Il nome del processo è un nome descrittivo per il processo, ad esempio Outlook, che non include l'estensione .exe o il percorso. GetProcessesByName è utile per ottenere e modificare tutti i processi associati allo stesso file eseguibile. Ad esempio, è possibile passare un nome di file eseguibile come processName parametro, per arrestare tutte le istanze in esecuzione del file eseguibile.

Anche se un processo Id è univoco per una singola risorsa di processo nel sistema, più processi nel computer locale possono eseguire l'applicazione specificata dal processName parametro . Restituisce GetProcessById quindi un processo al massimo, ma GetProcessesByName restituisce una matrice contenente tutti i processi associati. Se è necessario modificare il processo usando chiamate API standard, è possibile eseguire query su ognuno di questi processi a sua volta per il relativo identificatore. Non è possibile accedere alle risorse di elaborazione solo tramite il nome del processo, ma dopo aver recuperato una matrice di Process componenti associati alle risorse del processo, è possibile avviare, terminare e modificare in caso contrario le risorse di sistema.

È possibile usare questo overload per ottenere processi nel computer locale e in un computer remoto. Usare "." per specificare il computer locale. Esiste un altro overload che usa il computer locale per impostazione predefinita.

È possibile accedere ai processi nei computer remoti solo per visualizzare informazioni, ad esempio statistiche, sui processi. Non è possibile chiudere, terminare (usando Kill) o avviare processi nei computer remoti.

Vedi anche

Si applica a

GetProcessesByName(String)

Crea una matrice di nuovi componenti Process e li associa a tutte le risorse di processo nel computer locale che condividono il nome del processo specificato.

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

Parametri

processName
String

Nome descrittivo del processo.

Valori restituiti

Matrice di tipo Process che rappresenta le risorse di processo che eseguono l'applicazione o il file specificato.

Eccezioni

Esistono problemi durante l'accesso alle API del contatore delle prestazioni usate per ottenere informazioni sul processo. Questa eccezione è specifica per Windows NT, Windows 2000 e Windows XP.

Esempio

Nell'esempio seguente vengono recuperate le informazioni del processo corrente, i processi in esecuzione nel computer locale, tutte le istanze del Blocco note in esecuzione nel computer locale e un processo specifico nel computer locale. Recupera quindi le informazioni per gli stessi processi in un computer remoto.

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

Commenti

Utilizzare questo metodo per creare una matrice di nuovi Process componenti e associarli a tutte le risorse di processo che eseguono lo stesso file eseguibile nel computer locale. Le risorse di processo devono esistere già nel computer, perché GetProcessesByName non crea risorse di sistema ma le associa ai componenti generati dall'applicazione Process . È processName possibile specificare un oggetto per un file eseguibile che non è attualmente in esecuzione nel computer locale, quindi la matrice restituita dal metodo può essere vuota.

Il nome del processo è un nome descrittivo per il processo, ad esempio Outlook, che non include l'estensione .exe o il percorso. GetProcessesByName è utile per ottenere e modificare tutti i processi associati allo stesso file eseguibile. Ad esempio, è possibile passare un nome di file eseguibile come processName parametro, per arrestare tutte le istanze in esecuzione del file eseguibile.

Anche se un processo Id è univoco per una singola risorsa di processo nel sistema, più processi nel computer locale possono eseguire l'applicazione specificata dal processName parametro . Restituisce GetProcessById quindi un processo al massimo, ma GetProcessesByName restituisce una matrice contenente tutti i processi associati. Se è necessario modificare il processo usando chiamate API standard, è possibile eseguire query su ognuno di questi processi a sua volta per il relativo identificatore. Non è possibile accedere alle risorse di elaborazione solo tramite il nome del processo, ma dopo aver recuperato una matrice di Process componenti associati alle risorse del processo, è possibile avviare, terminare e modificare in caso contrario le risorse di sistema.

Vedi anche

Si applica a