Process.GetProcessesByName Metódus

Definíció

Új összetevők tömbjét Process hozza létre, és társítja őket a meglévő folyamaterőforrásokkal, amelyek mindegyike a megadott folyamatnevet használja.

Túlterhelések

Name Description
GetProcessesByName(String)

Új összetevők tömbjét Process hozza létre, és társítja őket a megadott folyamatnevet megosztó helyi számítógépen található összes folyamaterőforrással.

GetProcessesByName(String, String)

Létrehoz egy tömböt az új Process összetevőkből, és társítja őket a megadott folyamatnevet megosztó távoli számítógépen található összes folyamaterőforrással.

GetProcessesByName(String)

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

Új összetevők tömbjét Process hozza létre, és társítja őket a megadott folyamatnevet megosztó helyi számítógépen található összes folyamaterőforrással.

public:
 static cli::array <System::Diagnostics::Process ^> ^ GetProcessesByName(System::String ^ processName);
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.Process[] GetProcessesByName(string? processName);
public static System.Diagnostics.Process[] GetProcessesByName(string? processName);
public static System.Diagnostics.Process[] GetProcessesByName(string processName);
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member GetProcessesByName : string -> System.Diagnostics.Process[]
static member GetProcessesByName : string -> System.Diagnostics.Process[]
Public Shared Function GetProcessesByName (processName As String) As Process()

Paraméterek

processName
String

A folyamat rövid neve.

Válaszok

Olyan típusú Process tömb, amely a megadott alkalmazást vagy fájlt futtató folyamaterőforrásokat jelöli.

Attribútumok

Kivételek

Problémákat tapasztal a folyamatinformációk lekéréséhez használt teljesítményszámláló API-k elérésekor. Ez a kivétel Windows NT- és 2000-Windows és Windows XP vonatkozik.

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 új Process összetevők tömbjét hozhatja létre, és társíthatja őket az összes olyan folyamaterőforráshoz, amely ugyanazt a végrehajtható fájlt futtatja a helyi számítógépen. A folyamaterőforrásoknak már létezniük kell a számítógépen, mert GetProcessesByName nem hoznak létre rendszererőforrásokat, hanem az alkalmazás által létrehozott Process összetevőkhöz társítják őket. Megadható processName egy olyan végrehajtható fájlhoz, amely jelenleg nem fut a helyi számítógépen, így a metódus által visszaadott tömb üres lehet.

A folyamat neve a folyamat rövid neve, például Outlook, amely nem tartalmazza a .exe bővítményt vagy az elérési utat. GetProcessesByName hasznos lehet az ugyanazon végrehajtható fájlhoz társított összes folyamat lekéréséhez és kezeléséhez. Átadhat például egy végrehajtható fájlnevet paraméterként processName a végrehajtható fájl összes futó példányának leállításához.

Bár a folyamat Id egyedi a rendszeren található egyetlen folyamaterőforráshoz, a helyi számítógépen több folyamat is futtathatja a processName paraméter által megadott alkalmazást. GetProcessById Ezért legfeljebb egy folyamatot ad vissza, de GetProcessesByName az összes kapcsolódó folyamatot tartalmazó tömböt ad vissza. Ha szabványos API-hívások használatával kell módosítania a folyamatot, az egyes folyamatokat lekérdezheti az azonosítójára vonatkozóan. A folyamaterőforrásokat csak a folyamatnéven keresztül érheti el, de miután lekérte a folyamaterőforrásokkal társított összetevők tömbjét Process , elindíthatja, megszüntetheti és egyéb módon módosíthatja a rendszererőforrásokat.

Lásd még

A következőre érvényes:

GetProcessesByName(String, String)

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

Létrehoz egy tömböt az új Process összetevőkből, és társítja őket a megadott folyamatnevet megosztó távoli számítógépen található összes folyamaterőforrással.

public:
 static cli::array <System::Diagnostics::Process ^> ^ GetProcessesByName(System::String ^ processName, System::String ^ machineName);
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.Process[] GetProcessesByName(string? processName, string machineName);
public static System.Diagnostics.Process[] GetProcessesByName(string? processName, string machineName);
public static System.Diagnostics.Process[] GetProcessesByName(string processName, string machineName);
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member GetProcessesByName : string * string -> System.Diagnostics.Process[]
static member GetProcessesByName : string * string -> System.Diagnostics.Process[]
Public Shared Function GetProcessesByName (processName As String, machineName As String) As Process()

Paraméterek

processName
String

A folyamat rövid neve.

machineName
String

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

Válaszok

Olyan típusú Process tömb, amely a megadott alkalmazást vagy fájlt futtató folyamaterőforrásokat jelöli.

Attribútumok

Kivételek

A machineName paraméter szintaxisa érvénytelen. Lehet, hogy nulla (0) hosszúságú.

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

Az operációs rendszer platformja nem támogatja ezt a műveletet távoli számítógépeken.

A kapcsolódási machineName kísérlet sikertelen volt.

-vagy-

Problémákat tapasztal a folyamatinformációk lekéréséhez használt teljesítményszámláló API-k elérésekor. Ez a kivétel Windows NT- és 2000-Windows és Windows XP vonatkozik.

Hiba történt egy mögöttes rendszer API elérésekor.

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 új Process összetevőkből álló tömböt hozhat létre, és társíthatja őket az összes olyan folyamaterőforráshoz, amely ugyanazt a végrehajtható fájlt futtatja a megadott számítógépen. A folyamaterőforrásoknak már létezniük kell a számítógépen, mert GetProcessesByName nem hoznak létre rendszererőforrásokat, hanem az alkalmazás által létrehozott Process összetevőkhöz társítják őket. Megadható processName egy olyan végrehajtható fájlhoz, amely jelenleg nem fut a helyi számítógépen, így a metódus által visszaadott tömb üres lehet.

A folyamat neve a folyamat rövid neve, például Outlook, amely nem tartalmazza a .exe bővítményt vagy az elérési utat. GetProcessesByName hasznos lehet az ugyanazon végrehajtható fájlhoz társított összes folyamat lekéréséhez és kezeléséhez. Átadhat például egy végrehajtható fájlnevet paraméterként processName a végrehajtható fájl összes futó példányának leállításához.

Bár a folyamat Id egyedi a rendszeren található egyetlen folyamaterőforráshoz, a helyi számítógépen több folyamat is futtathatja a processName paraméter által megadott alkalmazást. GetProcessById Ezért legfeljebb egy folyamatot ad vissza, de GetProcessesByName az összes kapcsolódó folyamatot tartalmazó tömböt ad vissza. Ha szabványos API-hívások használatával kell módosítania a folyamatot, az egyes folyamatokat lekérdezheti az azonosítójára vonatkozóan. A folyamaterőforrásokat csak a folyamatnéven keresztül érheti el, de miután lekérte a folyamaterőforrásokkal társított összetevők tömbjét Process , elindíthatja, megszüntetheti és egyéb módon módosíthatja a rendszererőforrásokat.

Ezzel a túlterheléssel a helyi számítógépen és a távoli számítógépen is lekérheti a folyamatokat. Használja a "." parancsot a helyi számítógép megadásához. Létezik egy másik túlterhelés, amely alapértelmezés szerint a helyi számítógépet használja.

A távoli számítógépeken futó folyamatokhoz csak a folyamatokkal kapcsolatos információk, például statisztikák megtekintéséhez férhet hozzá. A távoli számítógépeken nem zárhatja be, nem állíthatja le (használhatja Kill) a folyamatokat, és nem indíthat el folyamatokat.

Lásd még

A következőre érvényes: