title: Cannot open Servicename service on computer '.'. Error on Starting Windows Service programatically using c#
body: <p>I have made a Windows Service and installed it on my system.Now as per my requirement i have to start and stop this windows Service using Button click from Windows Form Application.
  Here is my Code ..</p>
  
  <pre><code>public partial class Form1 : Form
  {
      string svcStatus;
      ServiceController myService;
  
      public Form1()
      {
          InitializeComponent();
  
          myService = new ServiceController();
          myService.ServiceName = "ServiceName";
          svcStatus = myService.Status.ToString();
      }
  
  
      private void button1_Click(object sender, EventArgs e)
      {
          if (svcStatus == "Stopped")
          {
              myService.Start();   // START the service if it is already Stopped
  
              string svcStatusWas = "";  
              while (svcStatus != "Running")
              {
                  if (svcStatus != svcStatusWas)
                  {
                      Console.WriteLine("Status: " + svcStatus);
                  }
  
                  svcStatusWas = svcStatus;
  
                  myService.Refresh();
                  svcStatus = myService.Status.ToString();
              }
              Console.WriteLine("Service Started!!");
          }
      }
  
      private void button2_Click(object sender, EventArgs e)
      {
          if (svcStatus == "Running")
          {                
              myService.Stop();   // STOP the service if it is already Running
  
              string svcStatusWas = "";   
              while (svcStatus != "Stopped")
              {
  
                  svcStatusWas = svcStatus;
  
                  myService.Refresh();    
                  svcStatus = myService.Status.ToString();
              }
              Console.WriteLine("Service Stopped!!");
          }
      }     
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I am getting error "Cannot open Servicename service on computer '.'." at this line myService.Start(); </p>
  
  <p>Please help me.</p>