title: Trying to start a windows service from a windows application giving System.ComponentModel.Win32Exception: Access is denied
body: <p>I am trying to develop a windows application to start/stop and monitor status of two particular services.  </p>
  
  <p>The problem is I am getting </p>
  
  <blockquote>
    <p>System.ComponentModel.Win32Exception:
    Access is denied</p>
  </blockquote>
  
  <p>Note that both services are local system </p>
  
  <p>The following is my code</p>
  
  <pre><code>private void StartService(string WinServiceName)
  {
    ServiceController sc = new ServiceController(WinServiceName,".");
  try
  {
    if (sc.ServiceName.Equals(WinServiceName))
    {
    //check if service stopped
      if (sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Stopped))
      {
         sc.Start();
      }
      else if (sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Paused))
      {
          sc.Start();
      }
    }
  
  }
  catch (Exception ex)
  {
    label3.Text = ex.ToString();
    MessageBox.Show("Could not start " + WinServiceName + "Service.\n Error : " + ex.ToString(), "Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
  }
  finally
  {
     sc.Close();
     sc.Dispose();
     // CheckStatus();
  }
  }
  </code></pre>