This code snippet shows how to stop a Windows Service using the service name. You will need to administer privileges to stop a service.
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceProcess;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
string serviceName = "Service Name";
ServiceController sController = new ServiceController(serviceName);
sController.Stop();
Console.WriteLine("Service stopped");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadKey();
}
}
}
No comments:
Post a Comment