Process.Id Property

Gets the unique identifier for the associated process.

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

[<MonitoringDescriptionAttribute("ProcessId")>]
member Id : int with get

Property Value

Type: System.Int32
The system-generated unique identifier of the process that is referenced by this Process instance.

ExceptionCondition
InvalidOperationException

The process's Id property has not been set.

-or-

There is no process associated with this Process object.

PlatformNotSupportedException

The platform is Windows 98 or Windows Millennium Edition (Windows Me); set the ProcessStartInfo.UseShellExecute property to false to access this property on Windows 98 and Windows Me.

The process Id is not valid if the associated process is not running. Therefore, you should ensure that the process is running before attempting to retrieve the Id property. Until the process terminates, the process identifier uniquely identifies the process throughout the system.

You can connect a process that is running on a local or remote computer to a new Process instance by passing the process identifier to the GetProcessById method. GetProcessById is a static method that creates a new component and sets the Id property for the new Process instance automatically.

Process identifiers can be reused by the system. The Id property value is unique only while the associated process is running. After the process has terminated, the system can reuse the Id property value for an unrelated process.

Because the identifier is unique on the system, you can pass it to other threads as an alternative to passing a Process instance. This action can save system resources yet guarantee that the process is correctly identified.

Windows 98, Windows Millennium Edition Platform Note: This property is not available on this platform if you started the process with ProcessStartInfo.UseShellExecute set to true.

The following example demonstrates how to obtain the Id for all running instances of an application. The code creates a new instance of Notepad, lists all the instances of Notepad, and then allows the user to enter the Id number to remove a specific instance.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

  • LinkDemand 

    for full trust for the immediate caller. This member cannot be used by partially trusted code.

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft