title: How do I install a windows service that runs as an administrator?
body: <p>I've written an installer that installs a windows service (A) that needs to start/stop another service (B). However, when A tries to start/stop B, I get this exception:</p>
  
  <p>System.InvalidOperationException: Cannot open MyService service on computer '.'. ---> System.ComponentModel.Win32Exception: Access is denied</p>
  
  <p>The installer installs the service as a local service, and it requests admin rights via the UAC pop-up, which I grant. I've also added an app.manifest file to the service that is set to ask for admin rights:</p>
  
  <p></p>
  
  <p>Yet I'm still getting that error.</p>
  
  <p>This is how I start the service (stopping is the same, except it calls Stop, of course):</p>
  
  <pre><code>using (Mutex mutex = new Mutex(false, "MyServiceLock"))
  {
      mutex.WaitOne();
  
      if (ServiceExists(serviceName) == true)
      {
          using (ServiceController serviceController = new ServiceController(serviceName, "."))
          {
              serviceController.Start(); // this line throws the exception
          }
      }
  
      mutex.ReleaseMutex();
  }
  </code></pre>
  
  <p>Why might access to this service be denied?</p>