How to open a Website in the default Browser in C# and VB.NET

To open a Website in the default Browser in C# and VB.NET you can use the snippet below.

Sample C#

System.Diagnostics.Process.Start("http://codesnippets.fesslersoft.de/");

Sample VB

System.Diagnostics.Process.Start("http://codesnippets.fesslersoft.de/")

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

How to kill a running process in C# and VB.NET

To kill a running process in C# and VB.NET you can use the following snippet.

Sample C#

public static void KillProcess(string name, bool waitForExit = true)
{
	foreach (var process in Process.GetProcessesByName(name))
	{
		try
		{
			process.Kill();
			if (waitForExit)
			{
				process.WaitForExit();
			}
		}
		catch (Exception ex)
		{
			//handle the exception your way
		}

	}
}

Sample VB.NET

Public Shared Sub KillProcess(name As String, Optional waitForExit As Boolean = True)
	For Each process__1 As var In Process.GetProcessesByName(name)
		Try
			process__1.Kill()
			If waitForExit Then
				process__1.WaitForExit()
			End If
				'handle the exception your way
		Catch ex As Exception

		End Try
	Next
End Sub