Process 类

定义

提供对本地和远程进程的访问权限并使你能够启动和停止本地系统进程。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.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
    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

        ' 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

        ' 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

        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
    End Class
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.

注解

Process 组件提供对计算机上运行的进程的访问。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. Process 组件用于访问系统进程。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. 若要直接释放类型,请在 try/finally 块中调用其 Dispose 方法。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. 操作系统将保留进程句柄,该句柄通过 Process 组件的 Handle 属性访问,即使进程已退出也是如此。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. 当直接调用方或派生类不具有完全信任权限时,将引发 SecurityExceptionA 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. 将对代码页程序集的引用添加到你的项目。Add a reference to the System.Text.Encoding.CodePages.dll assembly to your project.

  2. 检索 CodePagesEncodingProvider.Instance 属性中的 EncodingProvider 对象。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 方法之前已注册了编码提供程序,则 Process 类将自动使用默认系统编码,而不是 UTF8。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 类的新实例。Initializes a new instance of the Process class.

属性

BasePriority

获取关联进程的基本优先级。Gets the base priority of the associated process.

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(继承自 Component)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
EnableRaisingEvents

获取或设置在进程终止时是否应引发 Exited 事件。Gets or sets whether the Exited event should be raised when the process terminates.

Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 Component)
ExitCode

获取关联进程终止时指定的值。Gets the value that the associated process specified when it terminated.

ExitTime

获取关联进程退出的时间。Gets the time that the associated process exited.

Handle

获取关联进程的本机句柄。Gets the native handle of the associated process.

HandleCount

获取由进程打开的句柄数。Gets the number of handles opened by the process.

HasExited

获取指示关联进程是否已终止的值。Gets a value indicating whether the associated process has been terminated.

Id

获取关联进程的唯一标识符。Gets the unique identifier for the associated process.

MachineName

获取关联进程正在其上运行的计算机的名称。Gets the name of the computer the associated process is running on.

MainModule

获取关联进程的主模块。Gets the main module for the associated process.

MainWindowHandle

获取关联进程主窗口的窗口句柄。Gets the window handle of the main window of the associated process.

MainWindowTitle

获取进程的主窗口标题。Gets the caption of the main window of the process.

MaxWorkingSet

获取或设置关联进程允许的最大工作集大小(以字节为单位)。Gets or sets the maximum allowable working set size, in bytes, for the associated process.

MinWorkingSet

获取或设置关联进程允许的最小工作集大小(以字节为单位)。Gets or sets the minimum allowable working set size, in bytes, for the associated process.

Modules

获取已由关联进程加载的模块。Gets the modules that have been loaded by the associated process.

NonpagedSystemMemorySize

获取为关联的进程分配的非分页系统内存量(以字节为单位)。Gets the amount of nonpaged system memory, in bytes, allocated for the associated process.

NonpagedSystemMemorySize64

获取为关联的进程分配的非分页系统内存量(以字节为单位)。Gets the amount of nonpaged system memory, in bytes, allocated for the associated process.

PagedMemorySize

获取为关联的进程分配的分页内存量(以字节为单位)。Gets the amount of paged memory, in bytes, allocated for the associated process.

PagedMemorySize64

获取为关联的进程分配的分页内存量(以字节为单位)。Gets the amount of paged memory, in bytes, allocated for the associated process.

PagedSystemMemorySize

获取为关联进程分配的可分页系统内存量(以字节为单位)。Gets the amount of pageable system memory, in bytes, allocated for the associated process.

PagedSystemMemorySize64

获取为关联进程分配的可分页系统内存量(以字节为单位)。Gets the amount of pageable system memory, in bytes, allocated for the associated process.

PeakPagedMemorySize

获取关联的进程使用的虚拟内存分页文件中的最大内存量(以字节为单位)。Gets the maximum amount of memory in the virtual memory paging file, in bytes, used by the associated process.

PeakPagedMemorySize64

获取关联的进程使用的虚拟内存分页文件中的最大内存量(以字节为单位)。Gets the maximum amount of memory in the virtual memory paging file, in bytes, used by the associated process.

PeakVirtualMemorySize

获取关联进程使用的最大虚拟内存量(以字节为单位)。Gets the maximum amount of virtual memory, in bytes, used by the associated process.

PeakVirtualMemorySize64

获取关联进程使用的最大虚拟内存量(以字节为单位)。Gets the maximum amount of virtual memory, in bytes, used by the associated process.

PeakWorkingSet

获取关联进程的峰值工作集大小(以字节为单位)。Gets the peak working set size for the associated process, in bytes.

PeakWorkingSet64

获取关联进程使用的最大物理内存量(以字节为单位)。Gets the maximum amount of physical memory, in bytes, used by the associated process.

PriorityBoostEnabled

获取或设置一个值,该值指示主窗口拥有焦点时是否应由操作系统暂时提升关联进程优先级。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

获取或设置关联进程的总体优先级类别。Gets or sets the overall priority category for the associated process.

PrivateMemorySize

获取为关联的进程分配的专用内存量(以字节为单位)。Gets the amount of private memory, in bytes, allocated for the associated process.

PrivateMemorySize64

获取为关联的进程分配的专用内存量(以字节为单位)。Gets the amount of private memory, in bytes, allocated for the associated process.

PrivilegedProcessorTime

获取此进程的特权处理器时间。Gets the privileged processor time for this process.

ProcessName

获取该进程的名称。Gets the name of the process.

ProcessorAffinity

获取或设置一些处理器,此进程中的线程可以按计划在这些处理器上运行。Gets or sets the processors on which the threads in this process can be scheduled to run.

Responding

获取指示进程的用户界面当前是否响应的值。Gets a value indicating whether the user interface of the process is responding.

SafeHandle

获取此进程的本机句柄。Gets the native handle to this process.

SessionId

获取关联进程的终端服务会话标识符。Gets the Terminal Services session identifier for the associated process.

Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(继承自 Component)
StandardError

获取用于读取应用程序错误输出的流。Gets a stream used to read the error output of the application.

StandardInput

获取用于写入应用程序输入的流。Gets a stream used to write the input of the application.

StandardOutput

获取用于读取应用程序文本输出的流。Gets a stream used to read the textual output of the application.

StartInfo

获取或设置要传递给 ProcessStart() 方法的属性。Gets or sets the properties to pass to the Start() method of the Process.

StartTime

获取关联进程启动的时间。Gets the time that the associated process was started.

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

获取在关联进程中运行的一组线程。Gets the set of threads that are running in the associated process.

TotalProcessorTime

获取此进程的总的处理器时间。Gets the total processor time for this process.

UserProcessorTime

获取此进程的用户处理器时间。Gets the user processor time for this process.

VirtualMemorySize

获取进程的虚拟内存大小(以字节为单位)。Gets the size of the process's virtual memory, in bytes.

VirtualMemorySize64

获取为关联进程分配的虚拟内存量(以字节为单位)。Gets the amount of the virtual memory, in bytes, allocated for the associated process.

WorkingSet

获取关联进程的物理内存使用量(以字节为单位)。Gets the associated process's physical memory usage, in bytes.

WorkingSet64

获取为关联的进程分配的物理内存量(以字节为单位)。Gets the amount of physical memory, in bytes, allocated for the associated process.

方法

BeginErrorReadLine()

在应用程序的重定向 StandardError 流上开始进行异步读取操作。Begins asynchronous read operations on the redirected StandardError stream of the application.

BeginOutputReadLine()

在应用程序的重定向 StandardOutput 流上开始进行异步读取操作。Begins asynchronous read operations on the redirected StandardOutput stream of the application.

CancelErrorRead()

取消在应用程序的重定向 StandardError 流上执行的异步读取操作。Cancels the asynchronous read operation on the redirected StandardError stream of an application.

CancelOutputRead()

取消在应用程序的重定向 StandardOutput 流上执行的异步读取操作。Cancels the asynchronous read operation on the redirected StandardOutput stream of an application.

Close()

释放与此组件关联的所有资源。Frees all the resources that are associated with this component.

CloseMainWindow()

通过向进程的主窗口发送关闭消息来关闭拥有用户界面的进程。Closes a process that has a user interface by sending a close message to its main window.

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()
Dispose(Boolean)

释放此进程使用的所有资源。Release all resources used by this process.

EnterDebugMode()

通过启用当前线程的本机属性 Process,将 SeDebugPrivilege 组件置于与以特殊模式运行的操作系统进程交互的状态。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)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetCurrentProcess()

获取新的 Process 组件并将其与当前活动的进程关联。Gets a new Process component and associates it with the currently active process.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetProcessById(Int32)

返回新的 Process 组件(给定本地计算机上某个进程的标识符)。Returns a new Process component, given the identifier of a process on the local computer.

GetProcessById(Int32, String)

返回新的 Process 组件(给定进程标识符和网络中计算机的名称)。Returns a new Process component, given a process identifier and the name of a computer on the network.

GetProcesses()

为本地计算机上的每个进程资源创建一个新的 Process 组件。Creates a new Process component for each process resource on the local computer.

GetProcesses(String)

为指定计算机上的每个进程资源创建一个新的 Process 组件。Creates a new Process component for each process resource on the specified computer.

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)

创建新的 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)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
Kill()

立即停止关联的进程。Immediately stops the associated process.

Kill(Boolean)

立即停止关联的进程,并可选择停止其子/后代进程。Immediately stops the associated process, and optionally its child/descendent processes.

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

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
OnExited()

引发 Exited 事件。Raises the Exited event.

Refresh()

放弃已缓存到进程组件的关联仅存的任何相关信息。Discards any information about the associated process that has been cached inside the process component.

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)

启动由包含进程启动信息(例如,要启动的进程的文件名)的参数指定的进程资源,并将该资源与新的 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)

通过指定文档或应用程序文件的名称来启动进程资源,并将资源与新的 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)

通过指定应用程序的名称和一组命令行参数来启动一个进程资源,并将该资源与新的 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)

通过指定应用程序的名称、用户名、密码和域来启动一个进程资源,并将该资源与新的 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)

通过指定应用程序的名称、一组命令行自变量、用户名、密码和域来启动一个进程资源,并将该资源与新的 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()

如果适用,则将进程的名称格式化为字符串,并与父组件类型组合。Formats the process's name as a string, combined with the parent component type, if applicable.

WaitForExit()

指示 Process 组件无限期地等待关联进程退出。Instructs the Process component to wait indefinitely for the associated process to exit.

WaitForExit(Int32)

指示 Process 组件在指定的毫秒数内等待关联进程退出。Instructs the Process component to wait the specified number of milliseconds for the associated process to exit.

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)

使 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

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)
ErrorDataReceived

当应用程序写入其重定向 StandardError 流中时发生。Occurs when an application writes to its redirected StandardError stream.

Exited

在进程退出时发生。Occurs when a process exits.

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.

适用于

另请参阅