title: Enable windows service programmatically
body: <p>I am trying to enable a windows service programmatically by modifying the value in registry as below. The value does change. However, I am not able to start the service after that because windows still seeing it as disabled.</p>
  
  <pre><code>public void EnabledTheService(string serviceName)
  {
      try
      {
          RegistryKey key = Registry.LocalMachine
                                     .OpenSubKey(@"SYSTEM\CurrentControlSet\Services\"
                                                         + serviceName, true);
          key.SetValue("Start", 2);                
      }
      catch (Exception ex)
      {
           Console.Write(ex.Message);
      }
  }
  
  public void StartService(string serviceName)
  {
      ServiceController service = new ServiceController(serviceName);
      try
      {
          service.Start();
          service.WaitForStatus(ServiceControllerStatus.Running, 
                                              new TimeSpan(0, 0, 0, 20));
      }
      catch (Exception ex)
      {
          Console.Write(ex.Message);
      }
  }
  </code></pre>