Process Process Process Process Class

定義

提供對本機和遠端處理序的存取,並讓您能夠啟動和停止本機系統處理序。Provides access to local and remote processes and enables you to start and stop local system processes.

public ref class Process : System::ComponentModel::Component
public class Process : System.ComponentModel.Component
type Process = class
    inherit Component
Public Class Process
Inherits Component
繼承

範例

下列範例使用的執行個體Process類別來啟動處理序。The following example uses an instance of the Process class to start a process.

#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

int main()
{
    Process^ myProcess = gcnew Process;

    try
    {
        myProcess->StartInfo->UseShellExecute = false;
        // You can start any process, HelloWorld is a do-nothing example.
        myProcess->StartInfo->FileName = "C:\\HelloWorld.exe";
        myProcess->StartInfo->CreateNoWindow = true;
        myProcess->Start();
        // This code assumes the process you are starting will terminate itself. 
        // Given that is is started without a window so you cannot terminate it 
        // on the desktop, it must terminate itself or you can do it programmatically
        // from this application using the Kill method.
    }
    catch ( Exception^ e ) 
    {
        Console::WriteLine( e->Message );
    }
}
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        public static void Main()
        {
            try
            {
                using (Process myProcess = new Process())
                {
                    myProcess.StartInfo.UseShellExecute = false;
                    // You can start any process, HelloWorld is a do-nothing example.
                    myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
                    myProcess.StartInfo.CreateNoWindow = true;
                    myProcess.Start();
                    // This code assumes the process you are starting will terminate itself. 
                    // Given that is is started without a window so you cannot terminate it 
                    // on the desktop, it must terminate itself or you can do it programmatically
                    // from this application using the Kill method.
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}
Imports System
Imports System.Diagnostics
Imports System.ComponentModel

Namespace MyProcessSample
    Class MyProcess
        Public Shared Sub Main()
            Try
                Using myProcess As New Process()

                    myProcess.StartInfo.UseShellExecute = False
                    ' You can start any process, HelloWorld is a do-nothing example.
                    myProcess.StartInfo.FileName = "C:\\HelloWorld.exe"
                    myProcess.StartInfo.CreateNoWindow = True
                    myProcess.Start()
                    ' This code assumes the process you are starting will terminate itself. 
                    ' Given that is is started without a window so you cannot terminate it 
                    ' on the desktop, it must terminate itself or you can do it programmatically
                    ' from this application using the Kill method.
                End Using
            Catch e As Exception
                Console.WriteLine((e.Message))
            End Try
        End Sub 'Main
    End Class
End Namespace

下列範例會使用Process類別本身和靜態Start方法來啟動處理程序。The following example uses the Process class itself and a static Start method to start a process.

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

// Opens the Internet Explorer application.
void OpenApplication(String^ myFavoritesPath)
{
    // Start Internet Explorer. Defaults to the home page.
    Process::Start("IExplore.exe");

    // Display the contents of the favorites folder in the browser.
    Process::Start(myFavoritesPath);
}

// Opens urls and .html documents using Internet Explorer.
void OpenWithArguments()
{
    // url's are not considered documents. They can only be opened
    // by passing them as arguments.
    Process::Start("IExplore.exe", "www.northwindtraders.com");

    // Start a Web page using a browser associated with .html and .asp files.
    Process::Start("IExplore.exe", "C:\\myPath\\myFile.htm");
    Process::Start("IExplore.exe", "C:\\myPath\\myFile.asp");
}

// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
void OpenWithStartInfo()
{
    ProcessStartInfo^ startInfo = gcnew ProcessStartInfo("IExplore.exe");
    startInfo->WindowStyle = ProcessWindowStyle::Minimized;
    Process::Start(startInfo);
    startInfo->Arguments = "www.northwindtraders.com";
    Process::Start(startInfo);
}

int main()
{
    // Get the path that stores favorite links.
    String^ myFavoritesPath = Environment::GetFolderPath(Environment::SpecialFolder::Favorites);
    OpenApplication(myFavoritesPath);
    OpenWithArguments();
    OpenWithStartInfo();
}
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        // Opens the Internet Explorer application.
        void OpenApplication(string myFavoritesPath)
        {
            // Start Internet Explorer. Defaults to the home page.
            Process.Start("IExplore.exe");

            // Display the contents of the favorites folder in the browser.
            Process.Start(myFavoritesPath);
        }

        // Opens urls and .html documents using Internet Explorer.
        void OpenWithArguments()
        {
            // url's are not considered documents. They can only be opened
            // by passing them as arguments.
            Process.Start("IExplore.exe", "www.northwindtraders.com");

            // Start a Web page using a browser associated with .html and .asp files.
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
        }

        // Uses the ProcessStartInfo class to start new processes,
        // both in a minimized mode.
        void OpenWithStartInfo()
        {
            ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
            startInfo.WindowStyle = ProcessWindowStyle.Minimized;

            Process.Start(startInfo);

            startInfo.Arguments = "www.northwindtraders.com";

            Process.Start(startInfo);
        }

        static void Main()
        {
            // Get the path that stores favorite links.
            string myFavoritesPath =
                Environment.GetFolderPath(Environment.SpecialFolder.Favorites);

            MyProcess myProcess = new MyProcess();

            myProcess.OpenApplication(myFavoritesPath);
            myProcess.OpenWithArguments();
            myProcess.OpenWithStartInfo();
        }
    }
}
Imports System.Diagnostics
Imports System.ComponentModel

Namespace MyProcessSample
    Class MyProcess
        ' Opens the Internet Explorer application.
        Public Sub OpenApplication(myFavoritesPath As String)
            ' Start Internet Explorer. Defaults to the home page.
            Process.Start("IExplore.exe")

            ' Display the contents of the favorites folder in the browser.
            Process.Start(myFavoritesPath)
        End Sub 'OpenApplication

        ' Opens urls and .html documents using Internet Explorer.
        Sub OpenWithArguments()
            ' url's are not considered documents. They can only be opened
            ' by passing them as arguments.
            Process.Start("IExplore.exe", "www.northwindtraders.com")

            ' Start a Web page using a browser associated with .html and .asp files.
            Process.Start("IExplore.exe", "C:\myPath\myFile.htm")
            Process.Start("IExplore.exe", "C:\myPath\myFile.asp")
        End Sub 'OpenWithArguments

        ' Uses the ProcessStartInfo class to start new processes,
        ' both in a minimized mode.
        Sub OpenWithStartInfo()
            Dim startInfo As New ProcessStartInfo("IExplore.exe")
            startInfo.WindowStyle = ProcessWindowStyle.Minimized

            Process.Start(startInfo)

            startInfo.Arguments = "www.northwindtraders.com"

            Process.Start(startInfo)
        End Sub 'OpenWithStartInfo

        Shared Sub Main()
            ' Get the path that stores favorite links.
            Dim myFavoritesPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)

            Dim myProcess As New MyProcess()

            myProcess.OpenApplication(myFavoritesPath)
            myProcess.OpenWithArguments()
            myProcess.OpenWithStartInfo()
        End Sub 'Main
    End Class 'MyProcess
End Namespace 'MyProcessSample

下列F#範例會定義runProc啟動的處理序的函式會擷取所有輸出和錯誤的資訊,並記錄的程序執行的毫秒數。The following F# example defines a runProc function that starts a process, captures all output and error information, and records the number of milliseconds that the process has run. runProc函式有三個參數: 若要啟動,引數提供給應用程式,並起始目錄的應用程式的名稱。The runProc function has three parameters: the name of application to launch, the arguments to supply to the application, and the starting directory.

open System
open System.Diagnostics

let runProc filename args startDir : seq<string> * seq<string> = 
    let timer = Stopwatch.StartNew()
    let procStartInfo = 
        ProcessStartInfo(
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            UseShellExecute = false,
            FileName = filename,
            Arguments = args
        )
    match startDir with | Some d -> procStartInfo.WorkingDirectory <- d | _ -> ()

    let outputs = System.Collections.Generic.List<string>()
    let errors = System.Collections.Generic.List<string>()
    let outputHandler f (_sender:obj) (args:DataReceivedEventArgs) = f args.Data
    use p = new Process(StartInfo = procStartInfo)
    p.OutputDataReceived.AddHandler(DataReceivedEventHandler (outputHandler outputs.Add))
    p.ErrorDataReceived.AddHandler(DataReceivedEventHandler (outputHandler errors.Add))
    let started = 
        try
            p.Start()
        with | ex ->
            ex.Data.Add("filename", filename)
            reraise()
    if not started then
        failwithf "Failed to start process %s" filename
    printfn "Started %s with pid %i" p.ProcessName p.Id
    p.BeginOutputReadLine()
    p.BeginErrorReadLine()
    p.WaitForExit()
    timer.Stop()
    printfn "Finished %s after %A milliseconds" filename timer.ElapsedMilliseconds
    let cleanOut l = l |> Seq.filter (fun o -> String.IsNullOrEmpty o |> not)
    cleanOut outputs,cleanOut errors

程式碼runProc函式由撰寫ImaginaryDevelopment而且經過Microsoft 公用授權The code for the runProc function was written by ImaginaryDevelopment and is available under the Microsoft Public License.

備註

AProcess元件提供存取權的電腦執行的處理程序。A Process component provides access to a process that is running on a computer. 處理序,最簡單的說,是執行中應用程式。A process, in the simplest terms, is a running app. 執行緒是作業系統會配置處理器時間的基本單位。A thread is the basic unit to which the operating system allocates processor time. 執行緒可以執行此程序,包括部分由另一個執行緒目前正在執行的程式任何的碼部分。A thread can execute any part of the code of the process, including parts currently being executed by another thread.

Process元件是一個有用的工具來啟動、 停止、 控制和監視應用程式。The Process component is a useful tool for starting, stopping, controlling, and monitoring apps. 您可以使用Process元件,以取得正在執行的處理程序的清單,或者您可以啟動新的處理序。You can use the Process component, to obtain a list of the processes that are running, or you can start a new process. AProcess元件用來存取系統處理序。A Process component is used to access system processes. 之後Process元件已經初始化,它可以用來取得執行程序的相關資訊。After a Process component has been initialized, it can be used to obtain information about the running process. 這類資訊包括的執行緒,載入的模組 (.dll 和.exe 檔案),並使用效能資訊,例如處理程序的記憶體數量。Such information includes the set of threads, the loaded modules (.dll and .exe files), and performance information such as the amount of memory the process is using.

此類型會實作IDisposable介面。This type implements the IDisposable interface. 當您完成使用型別時,您應該處置它直接或間接。When you have finished using the type, you should dispose of it either directly or indirectly. 若要直接處置型別,呼叫其Dispose方法中的try / finally區塊。To dispose of the type directly, call its Dispose method in a try/finally block. 若要處置它間接,使用的語言建構這類using(在 C# 中) 或Using(在 Visual Basic)。To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). 如需詳細資訊,請參閱 「 使用物件,實作 IDisposable 」 一節IDisposable介面 > 主題。For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

注意

32 位元處理序無法存取 64 位元處理序的模組。32-bit processes cannot access the modules of a 64-bit process. 如果您嘗試從 32 位元處理序取得 64 位元處理程序的相關資訊,您會收到Win32Exception例外狀況。If you try to get information about a 64-bit process from a 32-bit process, you will get a Win32Exception exception. 相反地,64 位元處理程序,可以存取 32 位元處理序的模組。A 64-bit process, on the other hand, can access the modules of a 32-bit process.

處理序元件會取得一組屬性的相關資訊全部一次。The process component obtains information about a group of properties all at once. 在後Process元件已取得的任何群組的一個成員的相關資訊,它會快取該群組中的其他屬性的值,並無法取得群組的其他成員相關的新資訊,直到您呼叫Refresh方法。After the Process component has obtained information about one member of any group, it will cache the values for the other properties in that group and not obtain new information about the other members of the group until you call the Refresh method. 因此,如果屬性值不保證能夠比上次呼叫任何新Refresh方法。Therefore, a property value is not guaranteed to be any newer than the last call to the Refresh method. 群組之細項具有作業系統相依性。The group breakdowns are operating-system dependent.

如果您有宣告在系統中使用引號括住路徑變數,您必須在啟動該位置中找到任何處理序時完整限定該路徑。If you have a path variable declared in your system using quotes, you must fully qualify that path when starting any process found in that location. 否則,系統將無法找到路徑。Otherwise, the system will not find the path. 例如,如果c:\mypath不在您的路徑,而且您新增使用引號: path = %path%;"c:\mypath",您必須完整限定在任何處理序c:\mypath時啟動它。For example, if c:\mypath is not in your path, and you add it using quotation marks: path = %path%;"c:\mypath", you must fully qualify any process in c:\mypath when starting it.

系統處理序是以唯一識別系統上處理序識別碼。A system process is uniquely identified on the system by its process identifier. 就像許多 Windows 資源,其控制代碼,可能不是唯一的電腦上也會識別處理程序。Like many Windows resources, a process is also identified by its handle, which might not be unique on the computer. 控制代碼是資源的泛型的詞彙,識別項。A handle is the generic term for an identifier of a resource. 作業系統仍然存在處理序控制代碼,可透過Handle屬性Process元件,即使在處理序已結束。The operating system persists the process handle, which is accessed through the Handle property of the Process component, even when the process has exited. 因此,您可以取得處理程序的系統管理資訊,例如ExitCode(通常是零的成功或非零的錯誤碼) 和ExitTimeThus, you can get the process's administrative information, such as the ExitCode (usually either zero for success or a nonzero error code) and the ExitTime. 控制代碼會是非常重要的資源,所以遺漏控制更 virulent 比流失記憶體。Handles are an extremely valuable resource, so leaking handles is more virulent than leaking memory.

注意

這個類別包含的連結要求和繼承要求套用到所有成員的類別層級。This class contains a link demand and an inheritance demand at the class level that applies to all members. ASecurityException立即呼叫端或衍生的類別不具有完全信任權限時,會擲回。A SecurityException is thrown when either the immediate caller or the derived class does not have full-trust permission. 如需安全性需求的詳細資訊,請參閱連結要求For details about security demands, see Link Demands.

.NET Core.NET Core 附註Notes

在.NET Framework 中,Process預設使用的類別Console編碼方式,通常是程式碼頁的編碼方式,輸入、 輸出和錯誤資料流。In the .NET Framework, the Process class by default uses Console encodings, which are typically code page encodings, for the input, output, and error streams. 取得範例程式碼,在系統上文化特性是英文 (美國),字碼頁 437 則是預設編碼方式Console類別。For example code, on systems whose culture is English (United States), code page 437 is the default encoding for the Console class. 不過,.NET Core.NET Core可以提供可用的只有這些編碼方式的有限的子集。However, .NET Core.NET Core may make only a limited subset of these encodings available. 如果發生這種情況,它會使用Encoding.UTF8做為預設的編碼方式。If this is the case, it uses Encoding.UTF8 as the default encoding.

如果Process物件相依於特定字碼頁編碼方式,您仍然可以在它們可執行下列作業之前呼叫任何Process方法:If a Process object depends on specific code page encodings, you can still make them available by doing the following before you call any Process methods:

  1. 您可以將 System.Text.Encoding.CodePages.dll 組件的參考加入專案。Add a reference to the System.Text.Encoding.CodePages.dll assembly to your project.

  2. 擷取EncodingProvider物件從CodePagesEncodingProvider.Instance屬性。Retrieve the EncodingProvider object from the CodePagesEncodingProvider.Instance property.

  3. 傳遞EncodingProvider物件至Encoding.RegisterProvider進行編碼的提供者所支援的其他編碼的方法。Pass the EncodingProvider object to the Encoding.RegisterProvider method to make the additional encodings supported by the encoding provider available.

Process類別會再自動使用預設系統編碼方式 」,而不 UTF8,前提是您註冊編碼提供者之前呼叫任何Process方法。The Process class will then automatically use the default system encoding rather than UTF8, provided that you have registered the encoding provider before calling any Process methods.

建構函式

Process() Process() Process() Process()

初始化 Process 類別的新執行個體。Initializes a new instance of the Process class.

屬性

BasePriority BasePriority BasePriority BasePriority

取得相關處理序的基礎優先權 (Base Priority)。Gets the base priority of the associated process.

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

取得包含 IContainerComponentGets the IContainer that contains the Component.

(Inherited from Component)
DesignMode DesignMode DesignMode DesignMode

取得值,指出 Component 目前是否處於設計模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
EnableRaisingEvents EnableRaisingEvents EnableRaisingEvents EnableRaisingEvents

取得或設定是否應該在處理序終止時引發 Exited 事件。Gets or sets whether the Exited event should be raised when the process terminates.

Events Events Events Events

取得附加在這個 Component 上的事件處理常式清單。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
ExitCode ExitCode ExitCode ExitCode

取得相關處理序終止時指定的值。Gets the value that the associated process specified when it terminated.

ExitTime ExitTime ExitTime ExitTime

取得相關的處理序結束的時間。Gets the time that the associated process exited.

Handle Handle Handle Handle

取得相關處理序的原生控制代碼。Gets the native handle of the associated process.

HandleCount HandleCount HandleCount HandleCount

取得處理序開啟的控制代碼數目。Gets the number of handles opened by the process.

HasExited HasExited HasExited HasExited

取得值,指出相關的處理序是否已經終止。Gets a value indicating whether the associated process has been terminated.

Id Id Id Id

取得相關處理序的唯一識別項。Gets the unique identifier for the associated process.

MachineName MachineName MachineName MachineName

取得相關處理序正在執行的所在電腦的名稱。Gets the name of the computer the associated process is running on.

MainModule MainModule MainModule MainModule

取得相關處理序的主要模組。Gets the main module for the associated process.

MainWindowHandle MainWindowHandle MainWindowHandle MainWindowHandle

取得相關處理序主視窗的視窗控制代碼。Gets the window handle of the main window of the associated process.

MainWindowTitle MainWindowTitle MainWindowTitle MainWindowTitle

取得處理序的主視窗標題。Gets the caption of the main window of the process.

MaxWorkingSet MaxWorkingSet MaxWorkingSet MaxWorkingSet

取得或設定關聯的處理序所允許的工作集大小上限,以位元組為單位。Gets or sets the maximum allowable working set size, in bytes, for the associated process.

MinWorkingSet MinWorkingSet MinWorkingSet MinWorkingSet

取得或設定關聯的處理序所允許的工作集大小下限,以位元組為單位。Gets or sets the minimum allowable working set size, in bytes, for the associated process.

Modules Modules Modules Modules

取得相關的處理序所載入的模組。Gets the modules that have been loaded by the associated process.

NonpagedSystemMemorySize NonpagedSystemMemorySize NonpagedSystemMemorySize NonpagedSystemMemorySize

取得配置給關聯處理序的未分頁系統記憶體量 (以位元組為單位)。Gets the amount of nonpaged system memory, in bytes, allocated for the associated process.

NonpagedSystemMemorySize64 NonpagedSystemMemorySize64 NonpagedSystemMemorySize64 NonpagedSystemMemorySize64

取得配置給關聯處理序的未分頁系統記憶體量 (以位元組為單位)。Gets the amount of nonpaged system memory, in bytes, allocated for the associated process.

PagedMemorySize PagedMemorySize PagedMemorySize PagedMemorySize

取得配置給關聯處理序的分頁記憶體量 (以位元組為單位)。Gets the amount of paged memory, in bytes, allocated for the associated process.

PagedMemorySize64 PagedMemorySize64 PagedMemorySize64 PagedMemorySize64

取得配置給關聯處理序的分頁記憶體量 (以位元組為單位)。Gets the amount of paged memory, in bytes, allocated for the associated process.

PagedSystemMemorySize PagedSystemMemorySize PagedSystemMemorySize PagedSystemMemorySize

取得配置給關聯處理序的可分頁系統記憶體量 (以位元組為單位)。Gets the amount of pageable system memory, in bytes, allocated for the associated process.

PagedSystemMemorySize64 PagedSystemMemorySize64 PagedSystemMemorySize64 PagedSystemMemorySize64

取得配置給關聯處理序的可分頁系統記憶體量 (以位元組為單位)。Gets the amount of pageable system memory, in bytes, allocated for the associated process.

PeakPagedMemorySize PeakPagedMemorySize PeakPagedMemorySize PeakPagedMemorySize

取得關聯處理序所使用之虛擬記憶體分頁檔的最大記憶體量 (以位元組為單位)。Gets the maximum amount of memory in the virtual memory paging file, in bytes, used by the associated process.

PeakPagedMemorySize64 PeakPagedMemorySize64 PeakPagedMemorySize64 PeakPagedMemorySize64

取得關聯處理序所使用之虛擬記憶體分頁檔的最大記憶體量 (以位元組為單位)。Gets the maximum amount of memory in the virtual memory paging file, in bytes, used by the associated process.

PeakVirtualMemorySize PeakVirtualMemorySize PeakVirtualMemorySize PeakVirtualMemorySize

取得關聯處理序所使用最大虛擬記憶體量 (以位元組為單位)。Gets the maximum amount of virtual memory, in bytes, used by the associated process.

PeakVirtualMemorySize64 PeakVirtualMemorySize64 PeakVirtualMemorySize64 PeakVirtualMemorySize64

取得關聯處理序所使用最大虛擬記憶體量 (以位元組為單位)。Gets the maximum amount of virtual memory, in bytes, used by the associated process.

PeakWorkingSet PeakWorkingSet PeakWorkingSet PeakWorkingSet

取得相關處理序工作集大小的最大值 (位元組)。Gets the peak working set size for the associated process, in bytes.

PeakWorkingSet64 PeakWorkingSet64 PeakWorkingSet64 PeakWorkingSet64

取得關聯處理序所使用最大實體記憶體量 (以位元組為單位)。Gets the maximum amount of physical memory, in bytes, used by the associated process.

PriorityBoostEnabled PriorityBoostEnabled PriorityBoostEnabled PriorityBoostEnabled

取得或設定值,指出作業系統是否應該在主視窗有焦點 (Focus) 時,暫時提高相關的處理序優先權。Gets or sets a value indicating whether the associated process priority should temporarily be boosted by the operating system when the main window has the focus.

PriorityClass PriorityClass PriorityClass PriorityClass

取得或設定相關處理序的整體優先權分類。Gets or sets the overall priority category for the associated process.

PrivateMemorySize PrivateMemorySize PrivateMemorySize PrivateMemorySize

取得配置給關聯處理序的私用記憶體量 (以位元組為單位)。Gets the amount of private memory, in bytes, allocated for the associated process.

PrivateMemorySize64 PrivateMemorySize64 PrivateMemorySize64 PrivateMemorySize64

取得配置給關聯處理序的私用記憶體量 (以位元組為單位)。Gets the amount of private memory, in bytes, allocated for the associated process.

PrivilegedProcessorTime PrivilegedProcessorTime PrivilegedProcessorTime PrivilegedProcessorTime

取得這個處理序使用處理器的授權時間。Gets the privileged processor time for this process.

ProcessName ProcessName ProcessName ProcessName

取得處理序的名稱。Gets the name of the process.

ProcessorAffinity ProcessorAffinity ProcessorAffinity ProcessorAffinity

取得或設定處理器,這個處理序中的執行緒可以在其上排程執行。Gets or sets the processors on which the threads in this process can be scheduled to run.

Responding Responding Responding Responding

取得值,指出處理序的使用者介面是否正在回應。Gets a value indicating whether the user interface of the process is responding.

SafeHandle SafeHandle SafeHandle SafeHandle

取得這個處理序的原生控制代碼。Gets the native handle to this process.

SessionId SessionId SessionId SessionId

取得相關處理序的終端機服務工作階段識別項。Gets the Terminal Services session identifier for the associated process.

Site Site Site Site

取得或設定 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)
StandardError StandardError StandardError StandardError

取得用來讀取應用程式錯誤輸出的資料流。Gets a stream used to read the error output of the application.

StandardInput StandardInput StandardInput StandardInput

取得用來寫入應用程式輸入的資料流。Gets a stream used to write the input of the application.

StandardOutput StandardOutput StandardOutput StandardOutput

取得用來讀取應用程式文字輸出的資料流。Gets a stream used to read the textual output of the application.

StartInfo StartInfo StartInfo StartInfo

取得或設定要傳遞給 ProcessStart() 方法的屬性。Gets or sets the properties to pass to the Start() method of the Process.

StartTime StartTime StartTime StartTime

取得相關的處理序啟動的時間。Gets the time that the associated process was started.

SynchronizingObject SynchronizingObject SynchronizingObject SynchronizingObject

取得或設定物件,用以封送處理因處理序結束事件而發出的事件處理常式呼叫。Gets or sets the object used to marshal the event handler calls that are issued as a result of a process exit event.

Threads Threads Threads Threads

取得正在相關的處理序中執行的執行緒集。Gets the set of threads that are running in the associated process.

TotalProcessorTime TotalProcessorTime TotalProcessorTime TotalProcessorTime

取得這個處理序的總處理器時間。Gets the total processor time for this process.

UserProcessorTime UserProcessorTime UserProcessorTime UserProcessorTime

取得這個處理序的使用者處理器時間。Gets the user processor time for this process.

VirtualMemorySize VirtualMemorySize VirtualMemorySize VirtualMemorySize

取得處理序的虛擬記憶體的大小 (以位元組為單位)。Gets the size of the process's virtual memory, in bytes.

VirtualMemorySize64 VirtualMemorySize64 VirtualMemorySize64 VirtualMemorySize64

取得配置給關聯處理序的虛擬記憶體量,以位元組為單位。Gets the amount of the virtual memory, in bytes, allocated for the associated process.

WorkingSet WorkingSet WorkingSet WorkingSet

取得相關處理序的實體記憶體使用量 (以位元組為單位)。Gets the associated process's physical memory usage, in bytes.

WorkingSet64 WorkingSet64 WorkingSet64 WorkingSet64

取得配置給關聯處理序的實體記憶體量,以位元組為單位。Gets the amount of physical memory, in bytes, allocated for the associated process.

方法

BeginErrorReadLine() BeginErrorReadLine() BeginErrorReadLine() BeginErrorReadLine()

在應用程式的重新導向 StandardError 資料流上開始非同步讀取作業。Begins asynchronous read operations on the redirected StandardError stream of the application.

BeginOutputReadLine() BeginOutputReadLine() BeginOutputReadLine() BeginOutputReadLine()

在應用程式的重新導向 StandardOutput 資料流上開始非同步讀取作業。Begins asynchronous read operations on the redirected StandardOutput stream of the application.

CancelErrorRead() CancelErrorRead() CancelErrorRead() CancelErrorRead()

在應用程式的重新導向 StandardError 資料流上取消非同步讀取作業。Cancels the asynchronous read operation on the redirected StandardError stream of an application.

CancelOutputRead() CancelOutputRead() CancelOutputRead() CancelOutputRead()

在應用程式的重新導向 StandardOutput 資料流上取消非同步讀取作業。Cancels the asynchronous read operation on the redirected StandardOutput stream of an application.

Close() Close() Close() Close()

釋放與這個元件相關的所有資源。Frees all the resources that are associated with this component.

CloseMainWindow() CloseMainWindow() CloseMainWindow() CloseMainWindow()

關閉有使用者介面的處理序,方法是傳送關閉訊息至其主視窗。Closes a process that has a user interface by sending a close message to its main window.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

釋放這個處理序使用的所有資源。Release all resources used by this process.

EnterDebugMode() EnterDebugMode() EnterDebugMode() EnterDebugMode()

啟用目前執行緒上的原生屬性 SeDebugPrivilege,將 Process 元件置於某種狀態,以便與使用特殊模式執行的作業系統處理序互動。Puts a Process component in state to interact with operating system processes that run in a special mode by enabling the native property SeDebugPrivilege on the current thread.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetCurrentProcess() GetCurrentProcess() GetCurrentProcess() GetCurrentProcess()

取得新的 Process 元件,並將其與目前現用處理序相關聯。Gets a new Process component and associates it with the currently active process.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetProcessById(Int32) GetProcessById(Int32) GetProcessById(Int32) GetProcessById(Int32)

傳回新的 Process 元件,需指定本機電腦上的處理序識別項。Returns a new Process component, given the identifier of a process on the local computer.

GetProcessById(Int32, String) GetProcessById(Int32, String) GetProcessById(Int32, String) GetProcessById(Int32, String)

傳回新的 Process 元件,需指定網路上電腦的處理序識別項和名稱。Returns a new Process component, given a process identifier and the name of a computer on the network.

GetProcesses() GetProcesses() GetProcesses() GetProcesses()

為本機電腦上的每個處理序資源建立新的 Process 元件。Creates a new Process component for each process resource on the local computer.

GetProcesses(String) GetProcesses(String) GetProcesses(String) GetProcesses(String)

為指定電腦上的每個處理序資源建立新的 Process 元件。Creates a new Process component for each process resource on the specified computer.

GetProcessesByName(String) GetProcessesByName(String) GetProcessesByName(String) GetProcessesByName(String)

建立新 Process 元件的陣列,並將其與本機電腦上共用指定處理序名稱的所有處理序資源相關聯。Creates an array of new Process components and associates them with all the process resources on the local computer that share the specified process name.

GetProcessesByName(String, String) GetProcessesByName(String, String) GetProcessesByName(String, String) GetProcessesByName(String, String)

建立新 Process 元件的陣列,並將其與遠端電腦上共用指定處理序名稱的所有處理序資源相關聯。Creates an array of new Process components and associates them with all the process resources on a remote computer that share the specified process name.

GetService(Type) GetService(Type) GetService(Type) GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
Kill() Kill() Kill() Kill()

立即停止相關的處理序。Immediately stops the associated process.

Kill(Boolean) Kill(Boolean) Kill(Boolean) Kill(Boolean)
LeaveDebugMode() LeaveDebugMode() LeaveDebugMode() LeaveDebugMode()

Process 元件離開可與使用特殊模式執行的作業系統處理序互動的狀態。Takes a Process component out of the state that lets it interact with operating system processes that run in a special mode.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnExited() OnExited() OnExited() OnExited()

引發 Exited 事件。Raises the Exited event.

Refresh() Refresh() Refresh() Refresh()

捨棄快取於處理序元件內之相關處理序的任何資訊。Discards any information about the associated process that has been cached inside the process component.

Start() Start() Start() Start()

啟動 (或重複使用) 這個 Process 元件的 StartInfo 屬性指定的處理序資源,並將其與元件相關聯。Starts (or reuses) the process resource that is specified by the StartInfo property of this Process component and associates it with the component.

Start(ProcessStartInfo) Start(ProcessStartInfo) Start(ProcessStartInfo) Start(ProcessStartInfo)

啟動含有處理序啟動資訊 (例如,要啟動之處理序的檔名) 的參數所指定的處理序資源,並將該資源與新的 Process 元件相關聯。Starts the process resource that is specified by the parameter containing process start information (for example, the file name of the process to start) and associates the resource with a new Process component.

Start(String) Start(String) Start(String) Start(String)

藉由指定文件或應用程式檔案的名稱啟動處理序資源,並將該資源與新的 Process 元件相關聯。Starts a process resource by specifying the name of a document or application file and associates the resource with a new Process component.

Start(String, String) Start(String, String) Start(String, String) Start(String, String)

藉由指定應用程式的名稱和一組命令列引數來啟動處理序資源,並將該資源與新的 Process 元件相關聯。Starts a process resource by specifying the name of an application and a set of command-line arguments, and associates the resource with a new Process component.

Start(String, String, SecureString, String) Start(String, String, SecureString, String) Start(String, String, SecureString, String) Start(String, String, SecureString, String)

藉由指定應用程式的名稱、使用者名稱、密碼和網域來啟動處理序資源,並將該資源與新的 Process 元件相關聯。Starts a process resource by specifying the name of an application, a user name, a password, and a domain and associates the resource with a new Process component.

Start(String, String, String, SecureString, String) Start(String, String, String, SecureString, String) Start(String, String, String, SecureString, String) Start(String, String, String, SecureString, String)

藉由指定應用程式的名稱、一組命令列引數、使用者名稱、密碼和網域來啟動處理序資源,並將該資源與新的 Process 元件相關聯。Starts a process resource by specifying the name of an application, a set of command-line arguments, a user name, a password, and a domain and associates the resource with a new Process component.

ToString() ToString() ToString() ToString()

將處理序的名稱格式化為字串,如果適用,將它和父代 (Parent) 元件類型結合。Formats the process's name as a string, combined with the parent component type, if applicable.

WaitForExit() WaitForExit() WaitForExit() WaitForExit()

指示 Process 元件無限期等候相關聯處理序結束。Instructs the Process component to wait indefinitely for the associated process to exit.

WaitForExit(Int32) WaitForExit(Int32) WaitForExit(Int32) WaitForExit(Int32)

指示 Process 元件等候相關聯處理序結束的指定毫秒數。Instructs the Process component to wait the specified number of milliseconds for the associated process to exit.

WaitForInputIdle() WaitForInputIdle() WaitForInputIdle() WaitForInputIdle()

Process 元件無限期等候相關聯處理序進入閒置狀態。Causes the Process component to wait indefinitely for the associated process to enter an idle state. 這個多載只適用於具有使用者介面和訊息迴圈的處理序。This overload applies only to processes with a user interface and, therefore, a message loop.

WaitForInputIdle(Int32) WaitForInputIdle(Int32) WaitForInputIdle(Int32) WaitForInputIdle(Int32)

Process 元件等候相關聯處理序進入閒置狀態的指定毫秒數。Causes the Process component to wait the specified number of milliseconds for the associated process to enter an idle state. 這個多載只適用於具有使用者介面和訊息迴圈的處理序。This overload applies only to processes with a user interface and, therefore, a message loop.

事件

Disposed Disposed Disposed Disposed

當此元件由 Dispose() 方法的呼叫處置時發生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
ErrorDataReceived ErrorDataReceived ErrorDataReceived ErrorDataReceived

發生於應用程式寫入至其重新導向的 StandardError 資料流時。Occurs when an application writes to its redirected StandardError stream.

Exited Exited Exited Exited

發生於處理序結束時。Occurs when a process exits.

OutputDataReceived OutputDataReceived OutputDataReceived OutputDataReceived

發生於應用程式將某行寫入至其重新導向的 StandardOutput 資料流時。Occurs each time an application writes a line to its redirected StandardOutput stream.

安全性

LinkDemand
針對完全信任立即呼叫端。for full trust for the immediate caller. 這個類別不能由部分信任的程式碼。This class cannot be used by partially trusted code.

InheritanceDemand
針對繼承者完全信任。for full trust for inheritors. 這個類別無法繼承由部分信任的程式碼。This class cannot be inherited by partially trusted code.

適用於

另請參閱