.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> System Process >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

kill windows service programmatically

Posted By:Amit Mehra       Posted Date: November 23, 2009    Points: 10    Category: System Process    URL: http://www.dotnetspark.com  

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


/// Find and kill the process

public static bool KillProcess(string name)
       foreach (Process process in Process.GetProcesses())
              if (process.ProcessName.StartsWith(name))
                    return true;
return false;

In VB.NET example function


''' Find and kill the process

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
Return True
End If
Return False
End Function



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend