Note that there are some explanatory texts on larger screens.

plurals
  1. PORestart NetworkService service from another service
    text
    copied!<p>I have a Windows service MyService (implemented in C#) that runs as NetworkService. MyService needs to start another third-party service TheirService which also runs as NetworkService. Attempt to start TheirService fails with an access denied error when attempted from MyService using this code:</p> <pre><code> public static bool StartService(string serviceName, TimeSpan timeout) { bool started = false; try { using (ServiceController sc = new ServiceController(serviceName)) { if (sc != null) { sc.Refresh(); if (sc.Status == ServiceControllerStatus.Running) { // Stop service Trace.TraceInformation("Util.StartService Stopping service '{0}'...", serviceName); sc.Stop(); } sc.WaitForStatus(ServiceControllerStatus.Stopped, timeout); sc.Refresh(); // Start service Trace.TraceInformation("Util.StartService Starting service '{0}'...", serviceName); sc.Start(); sc.WaitForStatus(ServiceControllerStatus.Running, timeout); sc.Refresh(); started = (sc.Status == ServiceControllerStatus.Running); } } } catch (Exception e) { Trace.TraceError("Util.StartService Exception occurred while starting service '{0}'.\n{1}\n{2}", serviceName, e.Message, e.StackTrace); } Trace.TraceInformation("Util.StartService Service '{0}' restarted? {1}", serviceName, started); return started; } </code></pre> <p>TheirService's SID info:</p> <pre><code>C:\&gt;sc showsid TheirService NAME: TheirService SERVICE SID: S-1-5-80-3034156332-2544749427-1608259134-1317875859-4063208518 </code></pre> <p>Is there a way to start TheirService from MyService programmatically from C#?</p> <p>EDIT: Goal - As part of MyService installation, I want to be able to restart TheirService.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload