Process.GetProcesses Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Crea una matrice di nuovi Process componenti e le associa alle risorse di processo esistenti.
Overload
| Nome | Descrizione |
|---|---|
| GetProcesses() |
Crea un nuovo componente Process per ogni risorsa di processo nel computer locale. |
| GetProcesses(String) |
Crea un nuovo componente Process per ogni risorsa di processo nel computer specificato. |
GetProcesses()
Crea un nuovo componente Process per ogni risorsa di processo nel computer locale.
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()
Valori restituiti
Matrice di tipo Process che rappresenta tutte le risorse di processo in esecuzione nel computer locale.
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 nel computer locale. Le risorse di processo devono esistere già nel computer locale, perché GetProcesses non crea risorse di sistema, ma associa le risorse ai componenti generati dall'applicazione Process . Poiché il sistema operativo stesso esegue processi in background, questa matrice non è mai vuota.
Se non si desidera recuperare tutti i processi in esecuzione nel computer, è possibile limitare il numero utilizzando il GetProcessById metodo o GetProcessesByName . GetProcessById crea un Process componente associato al processo identificato nel sistema dall'identificatore del processo passato al metodo . GetProcessesByName crea una matrice di componenti le cui risorse di Process processo associate condividono il file eseguibile passato al metodo .
Note
È possibile caricare più servizi Windows all'interno della stessa istanza del processo host del servizio (svchost.exe). GetProcesses non identifica i singoli servizi; per questo, vedere GetServices.
Vedi anche
Si applica a
GetProcesses(String)
Crea un nuovo componente Process per ogni risorsa di processo nel computer specificato.
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
Computer da cui leggere l'elenco dei processi.
Valori restituiti
Matrice di tipo Process che rappresenta tutte le risorse di processo in esecuzione nel computer 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.
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 nel computer specificato (in genere remoto). Le risorse di processo devono esistere già nel computer locale, perché GetProcesses non crea risorse di sistema, ma associa le risorse ai componenti generati dall'applicazione Process . Poiché il sistema operativo stesso esegue processi in background, questa matrice non è mai vuota.
Se non si desidera recuperare tutti i processi in esecuzione nel computer, è possibile limitare il numero utilizzando il GetProcessById metodo o GetProcessesByName . GetProcessById crea un Process componente associato al processo identificato nel sistema dall'identificatore del processo passato al metodo . GetProcessesByName crea una matrice di componenti le cui risorse di Process processo associate condividono il file eseguibile passato al metodo .
Questo overload del GetProcesses metodo viene in genere usato per recuperare l'elenco delle risorse di processo in esecuzione in un computer remoto in rete, ma è possibile specificare il computer locale passando ".".
Note
È possibile caricare più servizi Windows all'interno della stessa istanza del processo host del servizio (svchost.exe). GetProcesses non identifica i singoli servizi; per questo, vedere GetServices.