Process.GetProcessById Metódus

Definíció

Létrehoz egy új Process összetevőt, és társítja azt a megadott meglévő folyamaterőforrással.

Túlterhelések

Name Description
GetProcessById(Int32)

Egy új Process összetevőt ad vissza a helyi számítógépen található folyamat azonosítója alapján.

GetProcessById(Int32, String)

Egy új Process összetevőt ad vissza, amely egy folyamatazonosítót és egy számítógép nevét adja vissza a hálózaton.

GetProcessById(Int32)

Forrás:
Process.cs
Forrás:
Process.cs
Forrás:
Process.cs
Forrás:
Process.cs
Forrás:
Process.cs

Egy új Process összetevőt ad vissza a helyi számítógépen található folyamat azonosítója alapján.

public:
 static System::Diagnostics::Process ^ GetProcessById(int processId);
public static System.Diagnostics.Process GetProcessById(int processId);
static member GetProcessById : int -> System.Diagnostics.Process
Public Shared Function GetProcessById (processId As Integer) As Process

Paraméterek

processId
Int32

A folyamaterőforrás rendszer-egyedi azonosítója.

Válaszok

A Process paraméter által processId azonosított helyi folyamaterőforráshoz társított összetevő.

Kivételek

A paraméter által processId megadott folyamat nem fut. Előfordulhat, hogy az azonosító lejárt.

Példák

Az alábbi példa beolvassa az aktuális folyamat adatait, a helyi számítógépen futó folyamatokat, a helyi számítógépen futó Jegyzettömb összes példányát és egy adott folyamatot a helyi számítógépen. Ezután lekéri a távoli számítógépen található folyamatokra vonatkozó információkat.

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

Megjegyzések

Ezzel a módszerrel létrehozhat egy új Process összetevőt, és hozzárendelheti egy folyamaterőforráshoz a helyi számítógépen. A folyamaterőforrásnak már léteznie kell a számítógépen, mert GetProcessById(Int32) nem hoz létre rendszererőforrást, hanem egy erőforrást társít egy alkalmazás által létrehozott Process összetevőhöz. A folyamat Id csak a számítógépen futó folyamathoz kérhető le. A folyamat leállása után kivételt vet ki, GetProcessById(Int32) ha lejárt azonosítót ad át.

Egy adott számítógépen a folyamat azonosítója egyedi. GetProcessById(Int32) legfeljebb egy folyamatot ad vissza. Ha egy adott alkalmazást futtató összes folyamatot le szeretne kapni, használja a következőt GetProcessesByName(String): . Ha a megadott alkalmazást futtató számítógépen több folyamat is létezik, GetProcessesByName(String) az összes kapcsolódó folyamatot tartalmazó tömböt ad vissza. Ezeket a folyamatokat az azonosítójuk alapján kérdezheti le. A folyamatazonosító a Windows Feladatkezelő Processes paneljén tekinthető meg. Az PID oszlop megjeleníti a folyamathoz rendelt folyamatazonosítót.

A processId paraméter egy Int32 (32 bites aláírt egész szám), bár a mögöttes Windows API egy DWORD (nem aláírt 32 bites egész szám) használ hasonló API-khoz. Ez történelmi okokból van.

Lásd még

A következőre érvényes:

GetProcessById(Int32, String)

Forrás:
Process.cs
Forrás:
Process.cs
Forrás:
Process.cs
Forrás:
Process.cs
Forrás:
Process.cs

Egy új Process összetevőt ad vissza, amely egy folyamatazonosítót és egy számítógép nevét adja vissza a hálózaton.

public:
 static System::Diagnostics::Process ^ GetProcessById(int processId, System::String ^ machineName);
public static System.Diagnostics.Process GetProcessById(int processId, string machineName);
static member GetProcessById : int * string -> System.Diagnostics.Process
Public Shared Function GetProcessById (processId As Integer, machineName As String) As Process

Paraméterek

processId
Int32

A folyamaterőforrás rendszer-egyedi azonosítója.

machineName
String

A hálózatban lévő számítógép neve.

Válaszok

A Process paraméter által processId azonosított távoli folyamaterőforráshoz társított összetevő.

Kivételek

A paraméter által processId megadott folyamat nem fut. Előfordulhat, hogy az azonosító lejárt.

-vagy-

A machineName paraméter szintaxisa érvénytelen. A név hossza lehet nulla (0).

A machineName paraméter a következő null: .

Példák

Az alábbi példa beolvassa az aktuális folyamat adatait, a helyi számítógépen futó folyamatokat, a helyi számítógépen futó Jegyzettömb összes példányát és egy adott folyamatot a helyi számítógépen. Ezután lekéri a távoli számítógépen található folyamatokra vonatkozó információkat.

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

Megjegyzések

Ezzel a módszerrel létrehozhat egy új Process összetevőt, és hozzárendelheti egy folyamaterőforráshoz egy távoli számítógépen a hálózaton. A folyamaterőforrásnak már léteznie kell a megadott számítógépen, mert GetProcessById(Int32, String) nem hoz létre rendszererőforrást, hanem egy erőforrást társít egy alkalmazás által létrehozott Process összetevőhöz. A folyamat Id csak a számítógépen futó folyamathoz kérhető le. A folyamat leállása után kivételt vet ki, GetProcessById(Int32, String) ha lejárt azonosítót ad át.

Egy adott számítógépen a folyamat azonosítója egyedi. GetProcessById(Int32, String) legfeljebb egy folyamatot ad vissza. Ha egy adott alkalmazást futtató összes folyamatot le szeretne kapni, használja a következőt GetProcessesByName(String): . Ha a megadott alkalmazást futtató számítógépen több folyamat is létezik, GetProcessesByName(String) az összes kapcsolódó folyamatot tartalmazó tömböt ad vissza. Ezeket a folyamatokat az azonosítójuk alapján kérdezheti le. A folyamatazonosító a Windows Feladatkezelő Processes paneljén tekinthető meg. Az PID oszlop megjeleníti a folyamathoz rendelt folyamatazonosítót.

Ha nem ad meg egy machineNameértéket, a rendszer a helyi számítógépet használja. Másik lehetőségként megadhatja a helyi számítógépet machineName a "." értékre vagy egy üres sztringre ("").

A processId paraméter egy Int32 (32 bites aláírt egész szám), bár a mögöttes Windows API egy DWORD (nem aláírt 32 bites egész szám) használ hasonló API-khoz. Ez történelmi okokból van.

Lásd még

A következőre érvényes: