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

Creates an array of new Process components, associating them with the existing process resources specified by the processName parameter.

Overload List

Creates an array of Process components that are associated with process resources on a remote computer. These process resources share the specified process name.

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

Creates an array of Process components that are associated with process resources on the local computer. These process resources share the specified process name.

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

Example [Visual Basic]

The following example gets all processes on the local computer that are running the application specified by the procName parameter (in this example, "notepad"), and trying to close each one down in turn by calling CloseMainWindow. CloseMainWindow is a request to close down, so the procedure forces a close using Kill if the call to CloseMainWindow returns false.

This example assumes that the procName passed in refers to an application that has a graphical interface, and hence a message loop. CloseMainWindow requires the associated process to have a message loop in order to send a window close message to the process.

Note   This example shows how to use one of the overloaded versions of GetProcessesByName. For other examples that may be available, see the individual overload topics.

[Visual Basic]

Private Sub StopProcesses(ByVal procName As String)
    'Declare a new process component.
    Dim myproc As System.Diagnostics.Process

    'Get all instances of Notepad that are open, attempt to close them.
    For Each myproc In Process.GetProcessesByName(processName)
        If Not myproc.CloseMainWindow Then
'If closing is not successful, then force termination.
myproc.Kill
        End If
    Next
End Sub

See Also

Process Class | Process Members | System.Diagnostics Namespace