This code snippet shows how to start 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.Start();
Console.WriteLine("Service started");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadKey();
}
}
}
No comments:
Post a Comment