Start and Stop Windows Services Programatically !!


public static void StartWindowService(string serviceName)
{
ProcessStartInfo processstartInfo = new ProcessStartInfo("sc.exe");
processstartInfo.Arguments =
string.Format(CultureInfo.InvariantCulture, "start {0} ", serviceName);
processstartInfo.RedirectStandardOutput =
true;
processstartInfo.UseShellExecute =
false;
using (System.Diagnostics.Process p = new System.Diagnostics.Process())
{
p.StartInfo = processstartInfo;
if (p.Start())
{
p.WaitForExit();
}
}
}
public static void StopWindowService(string serviceName)
{
ProcessStartInfo processstartInfo = new ProcessStartInfo("sc.exe");
processstartInfo.Arguments =
string.Format(CultureInfo.InvariantCulture, "stop {0} ", serviceName);
processstartInfo.RedirectStandardOutput =
true;
processstartInfo.UseShellExecute =
false;
using (System.Diagnostics.Process p = new System.Diagnostics.Process())
{
p.StartInfo = processstartInfo;
if (p.Start())
{
p.WaitForExit();
}
}
}