4.17. Terminate a Process

Problem

You need to terminate a process such as an application or a service.

Solution

Obtain a Process object representing the operating system process you want to terminate. For Windows-based applications, call Process.CloseMainWindow to send a close message to the application's main window. For Windows-based applications that ignore CloseMainWindow, or for non- Windows-based applications, call the Process.Kill method.

How It Works

If you start a new process from managed code using the Process class (discussed in recipe 4-16), you can terminate the process using the Process object that represents the new process. You can also obtain Process objects that refer to other currently running processes using the Shared methods ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.