you need
  • - Microsoft Visual Studio.
Guide
1
Import namespace System, System.Diagnostics and System.Threading.At the beginning of the module, add the following line of code:

Imports System
Imports System.Diagnostics
Imports System.Threading

It is simply for ease of use of components specific to the namespace.
2
Get details of the process that must be closed.Use an object of class System.Diagnostics.Process.Declare a variable of this class:

Dim oProc As Process

then use any method to find the necessary process.
3
If the program in the future will need to be
closed, started to develop applications, you just save the object that is returned when you run the Start method:

oProc = Process.Start ("app.exe")
4
If you want to close the process ID, use the static method GetProcessById Process class to obtain the corresponding object:

oProc = Process.GetProcessById (nID)

There nID - the numeric identifier of the process.
5
If you know only some of the characteristics of the target process, make a search for it.Get a list of processes running on the local machine as an array of objects of class Process.Use techniques GetProcesses (returns all processes) or GetProcessesByName (only processes with the specified name):

Dim aoAllProcesses As Process () = Process.GetProcesses ()
Dim aoProcsByName As Process () = Process.GetProcessesByName ("app.exe")

List array objects using cycle:

Dim oProc As Process
For Each oProc In aoAllProcesses
'actions on oProc
Next

In a series of analyzes the properties MainModule, MainWindowTitle, ProcessName, etc.to find the desired object.
6
Try to complete the program by sending the message closing its main window.Call the CloseMainWindow object corresponding to the target process.If necessary, waiting for completion of an application by calling WaitForExit, for example:

oProc.CloseMainWindow ()
oProc.WaitForExit ()

This method does not guarantee the completion of the program, close the window because the message is processed and often can be ignored.
7
If necessary, guarantee the completion of the program after the call waiting CloseMainWindow perform in a short period of time.Use the Sleep method of class Thread.Then check the state of the process, analyzing HasExited property and if it is not completed, call the Kill:

Thread.Sleep (6000)
oProc.Refresh ()
If not oProc.HasExited Then
oProc.Kill ()
End If

If desired, you can carry out a survey of the state in the cycle, giving periodic requests the user to complete the application without saving the data.And just in case the consent of the call Kill.
8
system resources after the program using the method Close:

oProc.Close ()
9
To avoid unexpected errors during execution of the application, place the entire algorithmClosing the program unit Try-Catch-End Try.If you want to implement a full-fledged exception handling with the output of diagnostic messages.