kill windows service programmatically.
This function will allow you to Kill Windows Services programmatically using C# or VB.NET. Below function will accept the Windows service name as string input parameter and using that name it will find and kill windows services and return you Boolean value true on successful and false on unsuccessful.
In C# code Sample
/// <summary>
/// Find and kill the process
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool KillProcess(string name)
{
foreach (Process process in Process.GetProcesses())
{
if (process.ProcessName.StartsWith(name))
{
process.Kill();
return true;
}
}
return false;
}
In VB.NET example function
''' <summary>
''' Find and kill the process
''' </summary>
''' <param name="name"></param>
''' <returns></returns>
Public Shared Function KillProcess(ByVal name As String) As Boolean
For Each process__1 As Process In Process.GetProcesses()
If process__1.ProcessName.StartsWith(name) Then
process__1.Kill()
Return True
End If
Next
Return False
End Function
Thanks,
Amit