How to exit an application in C# and VB.NET

To exit an application in C# and VB.NET you can use the following snippet.

Sample C#

System.Windows.Forms.Application.Exit(0); // WINFORM
Environment.Exit(0); // CONSOLE APP
Application.Shutdown(); // WPF

Sample VB.NET

System.Windows.Forms.Application.[Exit](0) ' WINFORM
Environment.[Exit](0) ' CONSOLE APP
Application.Shutdown() ' WPF

How to start a process and wait for exit in Powershell

To start a application and wait for exit in Powershell you can use the following snippet.

Sample Powershell

start-process -filepath "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" -Wait -NoNewWindow -argumentlist '-args'

for more informations take a look at the MSDN Start-Process

How to kill a process in Batch

To kill a process in Batch you can use the snippets below.
If you dont know how to retrieve the PID you can use our other snippet List all Processes in Batch.

Sample Batches

taskkill /PID 1292

if you want to force the taskkill you can use /F.

taskkill /F /PID 1292

if you want to taskkill the process by name you can use the follwoing snippet.

taskkill /im notepad++.exe

for more informations see the msdn TASKKILL