Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Process Class

Provides access to local and remote processes and enables you to start and stop local system processes.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)

[HostProtectionAttribute(SecurityAction::LinkDemand, SharedState = true, Synchronization = true, 
	ExternalProcessMgmt = true, SelfAffectingProcessMgmt = true)]
[PermissionSetAttribute(SecurityAction::LinkDemand, Name = L"FullTrust")]
[PermissionSetAttribute(SecurityAction::InheritanceDemand, Name = L"FullTrust")]
public ref class Process : public Component

NoteNote:

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: SharedState | Synchronization | ExternalProcessMgmt | SelfAffectingProcessMgmt. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

NoteNote:

Starting with the .NET Framework version 2.0, the ability to reference performance counter data on other computers has been eliminated for many of the .NET Framework methods and properties. This change was made to improve performance and to enable non-administrators to use the Process class. As a result, some applications that did not get exceptions in earlier versions of the .NET Framework may now get a NotSupportedException. The methods and properties affected are too numerous to list here, but the exception information has been added to the affected member topics.

A Process component provides access to a process that is running on a computer. A process, in the simplest terms, is a running application. 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.

The Process component is a useful tool for starting, stopping, controlling, and monitoring applications. Using the Process component, you can obtain a list of the processes that are running, or you can start a new process. A Process component is used to access system processes. After a Process component has been initialized, it can be used to obtain information about the running process. 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.

NoteNote:

A 32-bit processes cannot access the modules of a 64-bit process. If you try to get information about a 64-bit process from a 32-bit process, you will get a Win32Exception exception.

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

The process component obtains information about a group of properties all at once. 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. 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.

A system process is uniquely identified on the system by its process identifier. 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. The operating system persists the process handle, which is accessed through the Handle property of the Process component, even when the process has exited. Thus, 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. Handles are an extremely valuable resource, so leaking handles is more virulent than leaking memory.

NoteNote:

This class contains a link demand and an inheritance demand at the class level that applies to all members. 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 and Inheritance Demands.

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
	{

		// Get the path that stores user documents.
		String^ myDocumentsPath = Environment::GetFolderPath( Environment::SpecialFolder::Personal );
		// You can start any process, HelloWorld is a do-nothing example.
		myProcess->StartInfo->FileName = "C:\\MyFile.doc";
		myProcess->StartInfo->UseShellExecute = false;
		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 );
	}
}

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

  • 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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0

Community Additions

Show:
© 2014 Microsoft