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


Top 5 Contributors of the Month
david stephan

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))
              {
                    process.Kill();
                    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
process__1.Kill()
Return True
End If
Next
Return False
End Function

Thanks,
Amit


     

Further Readings:

Responses

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