Process.GetProcessById Yöntem

Tanım

Yeni Process bir bileşen oluşturur ve bunu belirttiğiniz mevcut işlem kaynağıyla ilişkilendirir.

Aşırı Yüklemeler

GetProcessById(Int32)

Yerel bilgisayardaki bir işlemin tanımlayıcısı göz önüne alındığında yeni Process bir bileşen döndürür.

GetProcessById(Int32, String)

İşlem tanımlayıcısı ve ağdaki bir bilgisayarın adı verilip yeni Process bir bileşen döndürür.

GetProcessById(Int32)

Yerel bilgisayardaki bir işlemin tanımlayıcısı göz önüne alındığında yeni Process bir bileşen döndürür.

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

Parametreler

processId
Int32

İşlem kaynağının sistem benzersiz tanımlayıcısı.

Döndürülenler

Process

Process parametresi tarafından processId tanımlanan yerel işlem kaynağıyla ilişkilendirilmiş bir bileşen.

Özel durumlar

parametresi tarafından processId belirtilen işlem çalışmıyor. Tanımlayıcının süresi dolmuş olabilir.

İşlem bu nesne tarafından başlatılmadı.

Ö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 bir bileşen oluşturmak ve yerel bilgisayardaki bir işlem kaynağıyla ilişkilendirmek için bu yöntemi kullanın. Sistem kaynağı oluşturmadığından, bir kaynağı uygulama tarafından oluşturulan Process bir bileşenle ilişkilendirdiğinden GetProcessById(Int32) işlem kaynağının bilgisayarda zaten mevcut olması gerekir. Bir işlem Id yalnızca bilgisayarda çalışmakta olan bir işlem için alınabilir. İşlem sonlandırıldıktan sonra süresi GetProcessById(Int32) dolmuş bir tanımlayıcı geçirirseniz bir özel durum oluşturur.

Belirli bir bilgisayarda, bir işlemin tanımlayıcısı benzersizdir. GetProcessById(Int32) en fazla bir işlem döndürür. Belirli bir uygulamayı çalıştıran tüm işlemleri almak istiyorsanız kullanın GetProcessesByName(String). Belirtilen uygulamayı çalıştıran bilgisayarda birden çok işlem varsa, GetProcessesByName(String) tüm ilişkili işlemleri içeren bir dizi döndürür. Bu işlemlerin her birini sırayla tanımlayıcısı için sorgulayabilirsiniz. İşlem tanımlayıcısı, Windows Görev Yöneticisi'nin Processes panelinde görüntülenebilir. PID sütunu, işleme atanan işlem tanımlayıcısını görüntüler.

Temel alınan processId Windows API'sinde benzer API'ler için bir (işaretsiz 32 bit tamsayı) kullanılsa da parametre bir Int32 DWORD (32 bit işaretli tamsayıdır). Bu geçmişe dönük nedenlerden dolayıdır.

Ayrıca bkz.

Şunlara uygulanır

GetProcessById(Int32, String)

İşlem tanımlayıcısı ve ağdaki bir bilgisayarın adı verilip yeni Process bir bileşen döndürür.

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

Parametreler

processId
Int32

İşlem kaynağının sistem benzersiz tanımlayıcısı.

machineName
String

Ağdaki bir bilgisayarın adı.

Döndürülenler

Process

Process parametresi tarafından processId tanımlanan bir uzak işlem kaynağıyla ilişkili bileşen.

Özel durumlar

parametresi tarafından processId belirtilen işlem çalışmıyor. Tanımlayıcının süresi dolmuş olabilir.

-veya-

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

machineName parametresidirnull.

İşlem bu nesne tarafından başlatılmadı.

Ö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 bir bileşen oluşturmak ve bunu ağdaki uzak bilgisayardaki bir işlem kaynağıyla ilişkilendirmek için bu yöntemi kullanın. Sistem kaynağı oluşturmadığından, bir kaynağı uygulama tarafından oluşturulan Process bir bileşenle ilişkilendirdiğindenGetProcessById(Int32, String), işlem kaynağının belirtilen bilgisayarda zaten mevcut olması gerekir. Bir işlem Id yalnızca bilgisayarda çalışmakta olan bir işlem için alınabilir. İşlem sonlandırıldıktan sonra süresi GetProcessById(Int32, String) dolmuş bir tanımlayıcı geçirirseniz bir özel durum oluşturur.

Belirli bir bilgisayarda, bir işlemin tanımlayıcısı benzersizdir. GetProcessById(Int32, String) en fazla bir işlem döndürür. Belirli bir uygulamayı çalıştıran tüm işlemleri almak istiyorsanız kullanın GetProcessesByName(String). Belirtilen uygulamayı çalıştıran bilgisayarda birden çok işlem varsa, GetProcessesByName(String) tüm ilişkili işlemleri içeren bir dizi döndürür. Bu işlemlerin her birini sırayla tanımlayıcısı için sorgulayabilirsiniz. İşlem tanımlayıcısı, Windows Görev Yöneticisi'nin Processes panelinde görüntülenebilir. PID sütunu, işleme atanan işlem tanımlayıcısını görüntüler.

belirtmezseniz machineName, yerel bilgisayar kullanılır. Alternatif olarak, "." değerine veya boş bir dizeye ("") ayarlayarak machineName yerel bilgisayarı belirtebilirsiniz.

Temel alınan processId Windows API'sinde benzer API'ler için bir (işaretsiz 32 bit tamsayı) kullanılsa da parametre bir Int32 DWORD (32 bit işaretli tamsayıdır). Bu geçmişe dönük nedenlerden dolayıdır.

Ayrıca bkz.

Şunlara uygulanır