title: Start A Remote Service From C#
body: <p>I'm using the following code in a C# WinForms app to start windows services on a remote PC</p>
  
  <pre><code>    public static List&lt;Service&gt; GetServices()
      {
          List&lt;Service&gt; Services = new List&lt;Service&gt;();
          ServiceController[] sc = ServiceController.GetServices(Server);
          foreach (var s in sc)
          {
             Services.Add(new Service { Name = s.ServiceName, Running = s.Status == ServiceControllerStatus.Running });
          }
          return Services;
      }
  
      public static bool StartService(string ServiceName)
      {
          try
          {
              ServiceController sc = new ServiceController(ServiceName, Server);
              sc.Start();
              sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 10));
              sc.Refresh();
              return sc.Status == ServiceControllerStatus.Running;
          }
          catch(Exception ex) { return false; }
      }
  </code></pre>
  
  <p>The GetServices method works fine when pointing at my local PC or at the remote PC. The StartService method however only works on my local PC, when run on the remote PC I get access denied. In this case the remote PC is a windows XP pro machine on the same domain and the user I'm running the app under has local admin rights on it.</p>
  
  <p>I'm not sure if this is an issue with my code or if my permissions are not correct.</p>
  
  <p>If this is a permissions issue please let me know and I'll try asking on ServerFault.</p>
  
  <p>Thanks</p>