Process.GetProcessesByName Metodo

Definizione

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

Overload

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 di 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 di processo specificato.

GetProcessesByName(String, String)

Origine:
Process.Linux.cs
Origine:
Process.Linux.cs
Origine:
Process.Linux.cs

Crea una matrice di nuovi componenti Process e li associa a tutte le risorse di processo in un computer remoto che condividono il nome di 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);
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.Process[] GetProcessesByName (string? processName, string machineName);
public static System.Diagnostics.Process[] GetProcessesByName (string processName, string machineName);
static member GetProcessesByName : string * string -> System.Diagnostics.Process[]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
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 della rete.

Restituisce

Una matrice di tipo Process che rappresenta le risorse di processo che eseguono l'applicazione o il file specificati.

Attributi

Eccezioni

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

Il valore del parametro machineName è null.

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

Il tentativo di connessione a machineName non è riuscito.

-oppure-

Si sono verificati problemi di accesso alle API del contatore di prestazioni usate per ottenere informazioni sul processo. Questa eccezion è specifica di 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.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

Commenti

Utilizzare questo metodo per creare una matrice di nuovi Process componenti e associarle a tutte le risorse di processo che eseguono lo stesso file eseguibile nel computer specificato. Le risorse di processo devono già esistere nel computer, perché GetProcessesByName non crea risorse di sistema, ma le associa ai componenti generati Process dall'applicazione. È processName possibile specificare un oggetto per un file eseguibile che non è attualmente in esecuzione nel computer locale, in modo che la matrice restituita dal metodo possa 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 una 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 i processi nei computer remoti.

Vedi anche

Si applica a

GetProcessesByName(String)

Origine:
Process.cs
Origine:
Process.cs
Origine:
Process.cs

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

public:
 static cli::array <System::Diagnostics::Process ^> ^ GetProcessesByName(System::String ^ processName);
public static System.Diagnostics.Process[] GetProcessesByName (string? processName);
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.Process[] GetProcessesByName (string? processName);
public static System.Diagnostics.Process[] GetProcessesByName (string processName);
static member GetProcessesByName : string -> System.Diagnostics.Process[]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member GetProcessesByName : string -> System.Diagnostics.Process[]
Public Shared Function GetProcessesByName (processName As String) As Process()

Parametri

processName
String

Nome descrittivo del processo.

Restituisce

Una matrice di tipo Process che rappresenta le risorse di processo che eseguono l'applicazione o il file specificati.

Attributi

Eccezioni

Si sono verificati problemi di accesso alle API del contatore di prestazioni usate per ottenere informazioni sul processo. Questa eccezion è specifica di 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.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

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 già esistere nel computer, perché GetProcessesByName non crea risorse di sistema, ma le associa ai componenti generati Process dall'applicazione. È processName possibile specificare un oggetto per un file eseguibile che non è attualmente in esecuzione nel computer locale, in modo che la matrice restituita dal metodo possa 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 una 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