Process.GetProcessesByName Metoda

Definicja

Tworzy tablicę nowych Process składników i kojarzy je z istniejącymi zasobami procesu, które mają określoną nazwę procesu.

Przeciążenia

GetProcessesByName(String, String)

Tworzy tablicę nowych Process składników i kojarzy je ze wszystkimi zasobami procesu na komputerze zdalnym, który współużytkuje określoną nazwę procesu.

GetProcessesByName(String)

Tworzy tablicę nowych Process składników i kojarzy je ze wszystkimi zasobami procesu na komputerze lokalnym, który współużytkuje określoną nazwę procesu.

GetProcessesByName(String, String)

Źródło:
Process.Linux.cs
Źródło:
Process.Linux.cs
Źródło:
Process.Linux.cs

Tworzy tablicę nowych Process składników i kojarzy je ze wszystkimi zasobami procesu na komputerze zdalnym, który współużytkuje określoną nazwę procesu.

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

Parametry

processName
String

Przyjazna nazwa procesu.

machineName
String

Nazwa komputera w sieci.

Zwraca

Tablica typu Process reprezentująca zasoby procesu z uruchomioną określoną aplikacją lub plikiem.

Atrybuty

Wyjątki

Składnia parametru jest nieprawidłowa machineName . Może mieć długość zero (0).

Parametr machineName to null.

Platforma systemu operacyjnego nie obsługuje tej operacji na komputerach zdalnych.

Próba nawiązania połączenia z machineName usługą nie powiodła się.

-lub-

Występują problemy z uzyskiwaniem dostępu do interfejsów API licznika wydajności używanych do uzyskiwania informacji o procesie. Ten wyjątek jest specyficzny dla systemów Windows NT, Windows 2000 i Windows XP.

Wystąpił problem podczas uzyskiwania dostępu do bazowego interfejsu API systemu.

Przykłady

Poniższy przykład pobiera informacje o bieżącym procesie, procesy uruchomione na komputerze lokalnym, wszystkie wystąpienia Notatnika uruchomione na komputerze lokalnym i określony proces na komputerze lokalnym. Następnie pobiera informacje o tych samych procesach na komputerze zdalnym.

#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

Uwagi

Użyj tej metody, aby utworzyć tablicę nowych Process składników i skojarzyć je ze wszystkimi zasobami procesu, które uruchamiają ten sam plik wykonywalny na określonym komputerze. Zasoby procesu muszą już istnieć na komputerze, ponieważ GetProcessesByName nie tworzy zasobów systemowych, ale raczej kojarzy je ze składnikami wygenerowanymi Process przez aplikację. Można processName określić dla pliku wykonywalnego, który nie jest obecnie uruchomiony na komputerze lokalnym, więc tablica zwracana przez metodę może być pusta.

Nazwa procesu jest przyjazną nazwą procesu, taką jak Outlook, która nie zawiera rozszerzenia .exe ani ścieżki. GetProcessesByName jest pomocna w przypadku pobierania i manipulowania wszystkimi procesami skojarzonymi z tym samym plikiem wykonywalnym. Na przykład można przekazać nazwę pliku wykonywalnego jako processName parametr, aby zamknąć wszystkie uruchomione wystąpienia tego pliku wykonywalnego.

Chociaż proces Id jest unikatowy dla pojedynczego zasobu procesu w systemie, wiele procesów na komputerze lokalnym może uruchamiać aplikację określoną przez processName parametr . GetProcessById W związku z tym zwraca co najwyżej jeden proces, ale GetProcessesByName zwraca tablicę zawierającą wszystkie skojarzone procesy. Jeśli musisz manipulować procesem przy użyciu standardowych wywołań interfejsu API, możesz wykonać zapytanie dotyczące każdego z tych procesów z kolei pod kątem jego identyfikatora. Nie można uzyskać dostępu do zasobów procesu za pośrednictwem samej nazwy procesu, ale po pobraniu tablicy składników skojarzonych Process z zasobami procesu można uruchomić, zakończyć i w inny sposób manipulować zasobami systemowymi.

To przeciążenie służy do pobierania procesów na komputerze lokalnym, a także na komputerze zdalnym. Użyj polecenia ".", aby określić komputer lokalny. Istnieje inne przeciążenie, które domyślnie używa komputera lokalnego.

Dostęp do procesów na komputerach zdalnych można uzyskać tylko w celu wyświetlenia informacji, takich jak statystyki, dotyczące procesów. Nie można zamknąć, zakończyć (przy użyciu Killmetody ) ani uruchomić procesów na komputerach zdalnych.

Zobacz też

Dotyczy

GetProcessesByName(String)

Źródło:
Process.cs
Źródło:
Process.cs
Źródło:
Process.cs

Tworzy tablicę nowych Process składników i kojarzy je ze wszystkimi zasobami procesu na komputerze lokalnym, który współużytkuje określoną nazwę procesu.

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

Parametry

processName
String

Przyjazna nazwa procesu.

Zwraca

Tablica typu Process reprezentująca zasoby procesu z uruchomioną określoną aplikacją lub plikiem.

Atrybuty

Wyjątki

Występują problemy z uzyskiwaniem dostępu do interfejsów API licznika wydajności używanych do uzyskiwania informacji o procesie. Ten wyjątek jest specyficzny dla systemów Windows NT, Windows 2000 i Windows XP.

Przykłady

Poniższy przykład pobiera informacje o bieżącym procesie, procesy uruchomione na komputerze lokalnym, wszystkie wystąpienia Notatnika uruchomione na komputerze lokalnym i określony proces na komputerze lokalnym. Następnie pobiera informacje o tych samych procesach na komputerze zdalnym.

#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

Uwagi

Użyj tej metody, aby utworzyć tablicę nowych Process składników i skojarzyć je ze wszystkimi zasobami procesu, które działają w tym samym pliku wykonywalnym na komputerze lokalnym. Zasoby procesu muszą już istnieć na komputerze, ponieważ GetProcessesByName nie tworzy zasobów systemowych, ale raczej kojarzy je ze składnikami wygenerowanymi Process przez aplikację. Można processName określić dla pliku wykonywalnego, który nie jest obecnie uruchomiony na komputerze lokalnym, więc tablica zwracana przez metodę może być pusta.

Nazwa procesu jest przyjazną nazwą procesu, taką jak Outlook, która nie zawiera rozszerzenia .exe ani ścieżki. GetProcessesByName jest pomocna w przypadku pobierania i manipulowania wszystkimi procesami skojarzonymi z tym samym plikiem wykonywalnym. Na przykład można przekazać nazwę pliku wykonywalnego jako processName parametr, aby zamknąć wszystkie uruchomione wystąpienia tego pliku wykonywalnego.

Chociaż proces Id jest unikatowy dla pojedynczego zasobu procesu w systemie, wiele procesów na komputerze lokalnym może uruchamiać aplikację określoną przez processName parametr . GetProcessById W związku z tym zwraca co najwyżej jeden proces, ale GetProcessesByName zwraca tablicę zawierającą wszystkie skojarzone procesy. Jeśli musisz manipulować procesem przy użyciu standardowych wywołań interfejsu API, możesz wykonać zapytanie dotyczące każdego z tych procesów z kolei pod kątem jego identyfikatora. Nie można uzyskać dostępu do zasobów procesu za pośrednictwem samej nazwy procesu, ale po pobraniu tablicy składników skojarzonych Process z zasobami procesu można uruchomić, zakończyć i w inny sposób manipulować zasobami systemowymi.

Zobacz też

Dotyczy