title: ServiceController permissions in Windows 7
body: <p>I have an application which consists of a service and an executable. Essentially it's a forms application that is responsible for starting and stopping a service under specific circumstances.</p>
  
  <p>On Windows XP the application manages this fine using the following code:</p>
  
  <pre><code>ServiceController controller = new ServiceController();
  controller.MachineName = ".";
  controller.ServiceName = "XXXXXXXXXX";
  controller.Stop();
  controller.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 10));
  controller.Start();
  </code></pre>
  
  <p>But on Windows 7, even though I've started the application as an administrator, I get the following exception:</p>
  
  <pre><code>System.InvalidOperationException: Cannot open XXXXXXXXXXXXX service on computer '.'. ---&gt; System.ComponentModel.Win32Exception: Access is denied
     --- End of inner exception stack trace ---
     at System.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess)
     at System.ServiceProcess.ServiceController.Start(String[] args)
     at System.ServiceProcess.ServiceController.Start()
  </code></pre>
  
  <p>Is there anything I can do programmatically to resolve this?</p>