Cet article a fait l’objet d’une traduction automatique. Pour afficher l’article en anglais, activez la case d’option Anglais. Vous pouvez également afficher le texte anglais dans une fenêtre contextuelle en faisant glisser le pointeur de la souris sur le texte traduit.
Traduction
Anglais

Process.GetCurrentProcess méthode ()

 

Date de publication : novembre 2016

Obtient un nouveau composant Process et l'associe au processus actuellement actif.

Espace de noms:   System.Diagnostics
Assembly:  System (dans System.dll)

public static Process GetCurrentProcess()

Valeur de retour

Type: System.Diagnostics.Process

Nouveau composant Process associé à la ressource de processus qui exécute l'application appelante.

Use this method to create a new T:System.Diagnostics.Process instance and associate it with the process resource on the local computer.

Like the similar M:System.Diagnostics.Process.GetProcessById(System.Int32,System.String), M:System.Diagnostics.Process.GetProcessesByName(System.String), and M:System.Diagnostics.Process.GetProcesses methods, M:System.Diagnostics.Process.GetCurrentProcess associates an existing resource with a new T:System.Diagnostics.Process component.

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. It then retrieves information for the same processes on a remote computer.

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

LinkDemand

for full trust for the immediate caller. This member cannot be used by partially trusted code.

.NET Framework
Disponible depuis 1.1
Retour au début
Afficher: