NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Process.GetProcesses ()

Creates a new Process component for each process resource on the local computer.

[Visual Basic]
Overloads Public Shared Function GetProcesses() As Process ()
[C#]
public static Process[] GetProcesses();
[C++]
public: static Process* GetProcesses() [];
[JScript]
public static function GetProcesses() : Process[];

Return Value

An array of type Process that represents all of the process resources running on the local computer.

Remarks

Use this method to create an array of new Process components and associate them with all of the process resources on the local computer. The process resources must already exist on the local computer, because GetProcesses does not create backend resources, but rather associates them with application-generated Process components. Because the operating system itself is running background processes, this array is never empty.

If you don't want to retrieve all processes running on the computer, you can restrict their number by using the GetProcessById or GetProcessesByName methods. GetProcessById creates a Process component that is associated with the specific process identified on the system by the processId value you pass into the method call. GetProcessesByName creates an array of Process components whose associated process resources share the executable file you pass as the processName argument into the method.

Because the GetProcesses method is static (in Visual Basic Shared), you do not need to create an instance of the Process component before you call the method. You can call the method on the Process class itself.

Example

We use Notepad and Internet Explorer because they open separate instances of the application in separate windows. Some applications, like Word, can open multiple instances in the same window and hence the same process.

It is most demonstrative to open multiple instances of Notepad and Internet Explorer before executing the code.

See Also

Process Class | Process Members | System.Diagnostics Namespace | Process.GetProcesses Overload List | MachineName | GetProcessById | GetProcessesByName | GetCurrentProcess