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

Definizione

Crea una matrice di nuovi componenti Process e li associa alle risorse di processo esistenti.Creates an array of new Process components and associates them with existing process resources.

Overload

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

Crea un nuovo componente Process per ciascuna risorsa di processo nel computer specificato.Creates a new Process component for each process resource on the specified computer.

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

Crea un nuovo componente Process per ciascuna risorsa di processo del computer locale.Creates a new Process component for each process resource on the local computer.

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

Crea un nuovo componente Process per ciascuna risorsa di processo nel computer specificato.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()

Parametri

machineName
String String String String

Computer da cui leggere l'elenco di processi.The computer from which to read the list of processes.

Restituisce

Matrice di tipo Process che rappresenta tutte le risorse di processo in esecuzione sul computer specificato.An array of type Process that represents all the process resources running on the specified computer.

Eccezioni

La sintassi del parametro machineName non è valida.The machineName parameter syntax is invalid. Potrebbe avere lunghezza zero (0).It might have length zero (0).

Il valore del parametro machineName è null.The machineName parameter is null.

La piattaforma del sistema operativo non supporta questa operazione in computer remoti.The operating system platform does not support this operation on remote computers.

Si sono verificati problemi di accesso alle API del contatore di prestazioni usate per ottenere informazioni sul processo.There are problems accessing the performance counter API's used to get process information. Questa eccezion è specifica di Windows NT, Windows 2000 e Windows XP.This exception is specific to Windows NT, Windows 2000, and Windows XP.

Si è verificato un problema durante l'accesso a un'API di sistema sottostante.A problem occurred accessing an underlying system API.

Esempi

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.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. Recupera quindi le informazioni per gli stessi processi in un computer remoto.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

Commenti

Utilizzare questo metodo per creare una matrice di nuovi Process componenti e associarli a tutte le risorse di processo nel computer specificato, in genere remoto.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. È necessario che le risorse di processo esistano già nel computer GetProcesses locale, perché non crea risorse di sistema, bensì associa le risorse Process ai componenti generati dall'applicazione.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. Poiché il sistema operativo stesso esegue processi in background, questa matrice non è mai vuota.Because the operating system itself is running background processes, this array is never empty.

Se non si desidera recuperare tutti i processi in esecuzione nel computer, è possibile limitarne il numero usando il GetProcessById metodo o. GetProcessesByNameIf 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. GetProcessByIdCrea un Process componente associato al processo identificato nel sistema dall'identificatore del processo passato al metodo.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. GetProcessesByNameCrea una matrice di Process componenti le cui risorse di processo associate condividono il file eseguibile passato al metodo.GetProcessesByName creates an array of Process components whose associated process resources share the executable file you pass to the method.

Questo overload del GetProcesses metodo viene in genere utilizzato per recuperare l'elenco delle risorse di processo in esecuzione in un computer remoto sulla rete, ma è possibile specificare il computer locale passando ".".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 ".".

Nota

È possibile caricare più servizi di Windows all'interno della stessa istanza del processo host del servizio (svchost. exe).Multiple Windows services can be loaded within the same instance of the Service Host process (svchost.exe). GetProcesses non identifica i singoli servizi; a tale proposito, GetServicesvedere.GetProcesses does not identify those individual services; for that, see GetServices.

Sicurezza

LinkDemand
per l'attendibilità totale per il chiamante immediato.for full trust for the immediate caller. Impossibile utilizzare questo membro in codice parzialmente attendibile.This member cannot be used by partially trusted code.

Vedi anche

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

Crea un nuovo componente Process per ciascuna risorsa di processo del computer locale.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()

Restituisce

Matrice di tipo Process che rappresenta tutte le risorse di processo in esecuzione sul computer locale.An array of type Process that represents all the process resources running on the local computer.

Esempi

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.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. Recupera quindi le informazioni per gli stessi processi in un computer remoto.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

Commenti

Utilizzare questo metodo per creare una matrice di nuovi Process componenti e associarli a tutte le risorse di processo nel computer locale.Use this method to create an array of new Process components and associate them with all the process resources on the local computer. È necessario che le risorse di processo esistano già nel computer GetProcesses locale, perché non crea risorse di sistema, bensì associa le risorse Process ai componenti generati dall'applicazione.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. Poiché il sistema operativo stesso esegue processi in background, questa matrice non è mai vuota.Because the operating system itself is running background processes, this array is never empty.

Se non si desidera recuperare tutti i processi in esecuzione nel computer, è possibile limitarne il numero usando il GetProcessById metodo o. GetProcessesByNameIf 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. GetProcessByIdCrea un Process componente associato al processo identificato nel sistema dall'identificatore del processo passato al metodo.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. GetProcessesByNameCrea una matrice di Process componenti le cui risorse di processo associate condividono il file eseguibile passato al metodo.GetProcessesByName creates an array of Process components whose associated process resources share the executable file you pass to the method.

Nota

È possibile caricare più servizi di Windows all'interno della stessa istanza del processo host del servizio (svchost. exe).Multiple Windows services can be loaded within the same instance of the Service Host process (svchost.exe). GetProcesses non identifica i singoli servizi; a tale proposito, GetServicesvedere.GetProcesses does not identify those individual services; for that, see GetServices.

Sicurezza

LinkDemand
per l'attendibilità totale per il chiamante immediato.for full trust for the immediate caller. Impossibile utilizzare questo membro in codice parzialmente attendibile.This member cannot be used by partially trusted code.

Vedi anche

Si applica a