Process.GetProcesses Método

Definición

Crea una matriz de nuevos componentes Process y los asocia a recursos de proceso existentes.Creates an array of new Process components and associates them with existing process resources.

Sobrecargas

GetProcesses()

Crea un nuevo componente Process para cada recurso de proceso del equipo local.Creates a new Process component for each process resource on the local computer.

GetProcesses(String)

Crea un nuevo componente Process para cada recurso de proceso en el equipo especificado.Creates a new Process component for each process resource on the specified computer.

GetProcesses()

Crea un nuevo componente Process para cada recurso de proceso del equipo local.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()

Devoluciones

Process[]

Matriz de tipo Process que representa todos los recursos del proceso que se ejecutan en el equipo local.An array of type Process that represents all the process resources running on the local computer.

Ejemplos

En el ejemplo siguiente se recupera información del proceso actual, los procesos que se ejecutan en el equipo local, todas las instancias del Bloc de notas que se ejecutan en el equipo local y un proceso específico en el equipo local.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. A continuación, recupera información para los mismos procesos en un equipo 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.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

Comentarios

Utilice este método para crear una matriz de nuevos Process componentes y asociarlos a todos los recursos de proceso del equipo local.Use this method to create an array of new Process components and associate them with all the process resources on the local computer. Los recursos de proceso ya deben existir en el equipo local, ya que no GetProcesses crea recursos del sistema, sino que asocia recursos con componentes generados por la aplicación Process .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. Dado que el propio sistema operativo está ejecutando procesos en segundo plano, esta matriz nunca está vacía.Because the operating system itself is running background processes, this array is never empty.

Si no desea recuperar todos los procesos que se ejecutan en el equipo, puede restringir el número mediante el GetProcessById método o GetProcessesByName .If 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. GetProcessById crea un Process componente que está asociado al proceso identificado en el sistema por el identificador de proceso que se pasa al método.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. GetProcessesByName crea una matriz de Process componentes cuyos recursos de proceso asociados comparten el archivo ejecutable que se pasa al método.GetProcessesByName creates an array of Process components whose associated process resources share the executable file you pass to the method.

Nota

Se pueden cargar varios servicios de Windows en la misma instancia del proceso de host de servicio (svchost.exe).Multiple Windows services can be loaded within the same instance of the Service Host process (svchost.exe). GetProcesses no identifica los servicios individuales; para ello, vea GetServices .GetProcesses does not identify those individual services; for that, see GetServices.

Consulte también

Se aplica a

GetProcesses(String)

Crea un nuevo componente Process para cada recurso de proceso en el equipo especificado.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()

Parámetros

machineName
String

Equipo desde el que se lee la lista de procesos.The computer from which to read the list of processes.

Devoluciones

Process[]

Matriz de tipo Process que representa todos los recursos del proceso que se ejecutan en el equipo especificado.An array of type Process that represents all the process resources running on the specified computer.

Excepciones

La sintaxis de parámetro machineName no es válida.The machineName parameter syntax is invalid. Puede tener longitud cero (0).It might have length zero (0).

El parámetro machineName es null.The machineName parameter is null.

La plataforma del sistema operativo no admite esta operación en equipos remotos.The operating system platform does not support this operation on remote computers.

Hay problemas de acceso a las API del contador de rendimiento que se usan para obtener información del proceso.There are problems accessing the performance counter APIs used to get process information. Esta excepción es específica de Windows NT, Windows 2000 y Windows XP.This exception is specific to Windows NT, Windows 2000, and Windows XP.

Se ha producido un problema al obtener acceso a una API del sistema subyacente.A problem occurred accessing an underlying system API.

Ejemplos

En el ejemplo siguiente se recupera información del proceso actual, los procesos que se ejecutan en el equipo local, todas las instancias del Bloc de notas que se ejecutan en el equipo local y un proceso específico en el equipo local.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. A continuación, recupera información para los mismos procesos en un equipo 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.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

Comentarios

Utilice este método para crear una matriz de nuevos Process componentes y asociarlos a todos los recursos de proceso del equipo especificado (normalmente 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. Los recursos de proceso ya deben existir en el equipo local, ya que no GetProcesses crea recursos del sistema, sino que asocia recursos con componentes generados por la aplicación Process .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. Dado que el propio sistema operativo está ejecutando procesos en segundo plano, esta matriz nunca está vacía.Because the operating system itself is running background processes, this array is never empty.

Si no desea recuperar todos los procesos que se ejecutan en el equipo, puede restringir el número mediante el GetProcessById método o GetProcessesByName .If 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. GetProcessById crea un Process componente que está asociado al proceso identificado en el sistema por el identificador de proceso que se pasa al método.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. GetProcessesByName crea una matriz de Process componentes cuyos recursos de proceso asociados comparten el archivo ejecutable que se pasa al método.GetProcessesByName creates an array of Process components whose associated process resources share the executable file you pass to the method.

Esta sobrecarga del GetProcesses método se usa generalmente para recuperar la lista de recursos de proceso que se ejecutan en un equipo remoto de la red, pero puede especificar el equipo local pasando ".".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

Se pueden cargar varios servicios de Windows en la misma instancia del proceso de host de servicio (svchost.exe).Multiple Windows services can be loaded within the same instance of the Service Host process (svchost.exe). GetProcesses no identifica los servicios individuales; para ello, vea GetServices .GetProcesses does not identify those individual services; for that, see GetServices.

Consulte también

Se aplica a