Process.GetProcessesByName Yöntem

Tanım

Yeni Process bileşenlerden oluşan bir dizi oluşturur ve bunları belirtilen işlem adını paylaşan mevcut işlem kaynaklarıyla ilişkilendirir.

Aşırı Yüklemeler

GetProcessesByName(String, String)

Yeni Process bileşenlerden oluşan bir dizi oluşturur ve bunları belirtilen işlem adını paylaşan uzak bir bilgisayardaki tüm işlem kaynaklarıyla ilişkilendirir.

GetProcessesByName(String)

Yeni Process bileşenlerden oluşan bir dizi oluşturur ve bunları belirtilen işlem adını paylaşan yerel bilgisayardaki tüm işlem kaynaklarıyla ilişkilendirir.

GetProcessesByName(String, String)

Kaynak:
Process.Linux.cs
Kaynak:
Process.Linux.cs
Kaynak:
Process.Linux.cs

Yeni Process bileşenlerden oluşan bir dizi oluşturur ve bunları belirtilen işlem adını paylaşan uzak bir bilgisayardaki tüm işlem kaynaklarıyla ilişkilendirir.

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

Parametreler

processName
String

İşlemin kolay adı.

machineName
String

Ağdaki bir bilgisayarın adı.

Döndürülenler

Belirtilen uygulama veya dosyayı çalıştıran işlem kaynaklarını temsil eden tür Process dizisi.

Öznitelikler

Özel durumlar

machineName Parametre söz dizimi geçersiz. Uzunluğu sıfır (0) olabilir.

machineName parametresidirnull.

İşletim sistemi platformu uzak bilgisayarlarda bu işlemi desteklemez.

bağlanma machineName girişimi başarısız oldu.

-veya-

İşlem bilgilerini almak için kullanılan performans sayacı API'lerine erişirken sorun var. Bu özel durum Windows NT, Windows 2000 ve Windows XP'ye özgüdür.

Temel alınan sistem API'lerine erişilirken bir sorun oluştu.

Örnekler

Aşağıdaki örnek geçerli işlemin, yerel bilgisayarda çalışan işlemlerin, yerel bilgisayarda çalışan tüm Not Defteri örneklerinin ve yerel bilgisayardaki belirli bir işlemin bilgilerini alır. Ardından, uzak bilgisayardaki aynı işlemlere ilişkin bilgileri alır.

#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

Açıklamalar

Yeni Process bileşenler dizisi oluşturmak ve bunları belirtilen bilgisayarda aynı yürütülebilir dosyayı çalıştıran tüm işlem kaynaklarıyla ilişkilendirmek için bu yöntemi kullanın. Sistem kaynakları oluşturmadığından ancak bunları uygulama tarafından oluşturulan Process bileşenlerle ilişkilendirdiğinden, GetProcessesByName işlem kaynaklarının bilgisayarda zaten mevcut olması gerekir. processName Şu anda yerel bilgisayarda çalışmayan bir yürütülebilir dosya için belirtilebilir, bu nedenle yöntemin döndürdüğü dizi boş olabilir.

İşlem adı, .exe uzantısını veya yolu içermeyen Outlook gibi işlem için kolay bir addır. GetProcessesByName , aynı yürütülebilir dosyayla ilişkili tüm işlemleri almak ve işlemek için yararlıdır. Örneğin, bu yürütülebilir dosyanın çalışan tüm örneklerini kapatmak için parametresi olarak processName yürütülebilir dosya adını geçirebilirsiniz.

Bir işlem Id sistemdeki tek bir işlem kaynağına özgü olsa da, yerel bilgisayardaki birden çok işlem parametresi tarafından processName belirtilen uygulamayı çalıştırabilir. Bu nedenle, GetProcessById en fazla bir işlem döndürür, ancak GetProcessesByName tüm ilişkili işlemleri içeren bir dizi döndürür. Standart API çağrılarını kullanarak işlemi işlemeniz gerekiyorsa, bu işlemlerin her birini sırayla tanımlayıcısı için sorgulayabilirsiniz. İşlem kaynaklarına yalnızca işlem adı üzerinden erişemezsiniz, ancak işlem kaynaklarıyla ilişkilendirilmiş bir bileşen dizisi Process aldıktan sonra sistem kaynaklarını başlatabilir, sonlandırabilir ve başka şekilde işleyebilirsiniz.

İşlemleri hem yerel bilgisayarda hem de uzak bir bilgisayarda almak için bu aşırı yüklemeyi kullanabilirsiniz. Yerel bilgisayarı belirtmek için "." kullanın. Varsayılan olarak yerel bilgisayarı kullanan başka bir aşırı yükleme vardır.

Uzak bilgisayarlardaki işlemlere yalnızca istatistikler gibi işlemler hakkındaki bilgileri görüntülemek için erişebilirsiniz. Uzak bilgisayarlarda işlemleri kapatamaz, sonlandıramaz (kullanarak Kill) veya başlatamazsınız.

Ayrıca bkz.

Şunlara uygulanır

GetProcessesByName(String)

Kaynak:
Process.cs
Kaynak:
Process.cs
Kaynak:
Process.cs

Yeni Process bileşenlerden oluşan bir dizi oluşturur ve bunları belirtilen işlem adını paylaşan yerel bilgisayardaki tüm işlem kaynaklarıyla ilişkilendirir.

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

Parametreler

processName
String

İşlemin kolay adı.

Döndürülenler

Belirtilen uygulama veya dosyayı çalıştıran işlem kaynaklarını temsil eden tür Process dizisi.

Öznitelikler

Özel durumlar

İşlem bilgilerini almak için kullanılan performans sayacı API'lerine erişirken sorun var. Bu özel durum Windows NT, Windows 2000 ve Windows XP'ye özgüdür.

Örnekler

Aşağıdaki örnek geçerli işlemin, yerel bilgisayarda çalışan işlemlerin, yerel bilgisayarda çalışan tüm Not Defteri örneklerinin ve yerel bilgisayardaki belirli bir işlemin bilgilerini alır. Ardından, uzak bilgisayardaki aynı işlemlere ilişkin bilgileri alır.

#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

Açıklamalar

Yeni Process bileşenler dizisi oluşturmak ve bunları yerel bilgisayarda aynı yürütülebilir dosyayı çalıştıran tüm işlem kaynaklarıyla ilişkilendirmek için bu yöntemi kullanın. Sistem kaynakları oluşturmadığından ancak bunları uygulama tarafından oluşturulan Process bileşenlerle ilişkilendirdiğinden, GetProcessesByName işlem kaynaklarının bilgisayarda zaten mevcut olması gerekir. processName Şu anda yerel bilgisayarda çalışmayan bir yürütülebilir dosya için belirtilebilir, bu nedenle yöntemin döndürdüğü dizi boş olabilir.

İşlem adı, .exe uzantısını veya yolu içermeyen Outlook gibi işlem için kolay bir addır. GetProcessesByName , aynı yürütülebilir dosyayla ilişkili tüm işlemleri almak ve işlemek için yararlıdır. Örneğin, bu yürütülebilir dosyanın çalışan tüm örneklerini kapatmak için parametresi olarak processName yürütülebilir dosya adını geçirebilirsiniz.

Bir işlem Id sistemdeki tek bir işlem kaynağına özgü olsa da, yerel bilgisayardaki birden çok işlem parametresi tarafından processName belirtilen uygulamayı çalıştırabilir. Bu nedenle, GetProcessById en fazla bir işlem döndürür, ancak GetProcessesByName tüm ilişkili işlemleri içeren bir dizi döndürür. Standart API çağrılarını kullanarak işlemi işlemeniz gerekiyorsa, bu işlemlerin her birini sırayla tanımlayıcısı için sorgulayabilirsiniz. İşlem kaynaklarına yalnızca işlem adı üzerinden erişemezsiniz, ancak işlem kaynaklarıyla ilişkilendirilmiş bir bileşen dizisi Process aldıktan sonra sistem kaynaklarını başlatabilir, sonlandırabilir ve başka şekilde işleyebilirsiniz.

Ayrıca bkz.

Şunlara uygulanır