Process.GetProcesses Yöntem

Tanım

Yeni Process bileşenler dizisi oluşturur ve bunları mevcut işlem kaynaklarıyla ilişkilendirir.

Aşırı Yüklemeler

GetProcesses()

Yerel bilgisayardaki her işlem kaynağı için yeni Process bir bileşen oluşturur.

GetProcesses(String)

Belirtilen bilgisayardaki her işlem kaynağı için yeni Process bir bileşen oluşturur.

GetProcesses()

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

Yerel bilgisayardaki her işlem kaynağı için yeni Process bir bileşen oluşturur.

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

Döndürülenler

Yerel bilgisayarda çalışan tüm işlem kaynaklarını temsil eden tür Process dizisi.

Öznitelikler

Ö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. Daha sonra uzak bir bilgisayarda 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 bilgisayardaki tüm işlem kaynaklarıyla ilişkilendirmek için bu yöntemi kullanın. Sistem kaynakları oluşturmadığından, kaynakları uygulama tarafından oluşturulan Process bileşenlerle ilişkilendirdiğindenGetProcesses, işlem kaynaklarının yerel bilgisayarda zaten mevcut olması gerekir. İşletim sisteminin kendisi arka plan işlemleri çalıştırdığından, bu dizi hiçbir zaman boş olmaz.

Bilgisayarda çalışan tüm işlemleri almak istemiyorsanız, veya GetProcessesByName yöntemini kullanarak GetProcessById bunların sayısını kısıtlayabilirsiniz. GetProcessById , yöntemine geçirdiğiniz işlem tanımlayıcısı tarafından sistemde tanımlanan işlemle ilişkili bir Process bileşen oluşturur. GetProcessesByName , ilişkili işlem kaynakları yöntemine geçirdiğiniz yürütülebilir dosyayı paylaşan bir bileşen dizisi Process oluşturur.

Not

Hizmet Ana Bilgisayarı işleminin (svchost.exe) aynı örneğine birden çok Windows hizmeti yüklenebilir. GetProcesses bu hizmetleri tek tek tanımlamaz; bunun için bkz GetServices. .

Ayrıca bkz.

Şunlara uygulanır

GetProcesses(String)

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

Belirtilen bilgisayardaki her işlem kaynağı için yeni Process bir bileşen oluşturur.

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

Parametreler

machineName
String

İşlem listesinin okunduğu bilgisayar.

Döndürülenler

Belirtilen bilgisayarda çalışan tüm 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.

İşlem bilgilerini almak için kullanılan performans sayacı API'lerine erişirken sorunlarla karşılaşılıyor. 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. Daha sonra uzak bir bilgisayarda 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 (genellikle uzak) bilgisayardaki tüm işlem kaynaklarıyla ilişkilendirmek için bu yöntemi kullanın. Sistem kaynakları oluşturmadığından, kaynakları uygulama tarafından oluşturulan Process bileşenlerle ilişkilendirdiğindenGetProcesses, işlem kaynaklarının yerel bilgisayarda zaten mevcut olması gerekir. İşletim sisteminin kendisi arka plan işlemleri çalıştırdığından, bu dizi hiçbir zaman boş olmaz.

Bilgisayarda çalışan tüm işlemleri almak istemiyorsanız, veya GetProcessesByName yöntemini kullanarak GetProcessById bunların sayısını kısıtlayabilirsiniz. GetProcessById , yöntemine geçirdiğiniz işlem tanımlayıcısı tarafından sistemde tanımlanan işlemle ilişkili bir Process bileşen oluşturur. GetProcessesByName , ilişkili işlem kaynakları yöntemine geçirdiğiniz yürütülebilir dosyayı paylaşan bir bileşen dizisi Process oluşturur.

Yöntemin GetProcesses bu aşırı yüklemesi genellikle ağdaki uzak bir bilgisayarda çalışan işlem kaynaklarının listesini almak için kullanılır, ancak "." geçirerek yerel bilgisayarı belirtebilirsiniz.

Not

Hizmet Ana Bilgisayarı işleminin (svchost.exe) aynı örneğine birden çok Windows hizmeti yüklenebilir. GetProcesses bu hizmetleri tek tek tanımlamaz; bunun için bkz GetServices. .

Ayrıca bkz.

Şunlara uygulanır