NetworkService として実行される Windows サービス MyService (C# で実装) があります。MyService は、NetworkService としても実行される別のサードパーティ サービス TheirService を開始する必要があります。次のコードを使用して MyService から試行すると、TheirService を開始しようとするとアクセス拒否エラーで失敗します。
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;
}
彼らのサービスの SID 情報:
C:\>sc showsid TheirService
NAME: TheirService
SERVICE SID: S-1-5-80-3034156332-2544749427-1608259134-1317875859-4063208518
C# からプログラムで MyService から TheirService を開始する方法はありますか?
編集: 目標 - MyService のインストールの一環として、TherService を再起動できるようにしたいと考えています。