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

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

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

 Subscribe to Code Snippets

How to determine if window service is running and also to stop it

Posted By:Rajshree       Posted Date: October 28, 2010    Points: 15    Category: System Process    URL: http://www.dotnetspark.com  

The ServiceController class makes it easy to retrieve information about a windows service and manipulate it. Here's some code. Before running this example, make sure you have added a reference to System.ServiceProcess

static void Main(string[] args)
       ServiceController controller = new ServiceController("SERVICENAME");

        if (controller.Status.Equals(ServiceControllerStatus.Running)
            && controller.CanStop)
            Console.WriteLine("Service Stopped");
    catch (Exception ex)


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