title: How can I restart a Windows service on Server 2019 Datacenter?
body: <p>I am restarting a Windows service successfully on Windows Home Edition, but when I run the app that restarts a Windows service on Windows Server 2019 Datacentre installation, I get this error:</p>
  <blockquote>
  <p>Error 103: The service did not respond to the start or control request in a timely fashion.</p>
  </blockquote>
  <pre class="lang-cs prettyprint-override"><code>public static void EndTask()
  {
      string taskname = &quot;serviceTask.exe&quot;;
      string processName = taskname.Replace(&quot;.exe&quot;, &quot;&quot;);
  
      foreach (Process process in Process.GetProcessesByName(processName))
      {
          process.Kill();
          process.WaitForExit();
          process.Dispose();
      }
  }
         
  msg = string.Empty;
  if (serviceName != &quot;&quot;)
  {
      ServiceController service = new ServiceController(serviceName);
      try
      {
          EndTask();
  
          int millisec1 = Environment.TickCount;
          TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
          var serviceExists = ServiceController.GetServices().Any(s =&gt; s.ServiceName == serviceName);
          if (serviceExists)
          {
              if (service.Status == ServiceControllerStatus.Running)
              {
                  service.Stop();
                  service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
              }
  
              // count the rest of the timeout
              int millisec2 = Environment.TickCount;
             timeout = TimeSpan.FromMilliseconds(timeoutMillisecond - (millisec2 - millisec1));
  
              service.Start();
              service.WaitForStatus(ServiceControllerStatus.Running, timeout);
          }
      }
      catch (Exception ex)
      {
          throw ex;
      }
  }
  else
  {
      msg = &quot;service not started&quot;;
  
  }
  </code></pre>
  <p>The user has admin rights and the service can be started and stopped from the Services panel but not from C#. This is the process I am using to restart. Is there something different that needs to be done on Server 2019?</p>