NetworkService로 실행되는 Windows 서비스 MyService (C#으로 구현 됨)가 있습니다. MyService는 NetworkService로 실행되는 다른 써드 파티 서비스 인 TheirService를 시작해야합니다. 이 코드를 사용하여이면 MyService에서 시도 할 때 TheirService가 액세스 거부 오류와 함께 실패 시작하려고 :다른 서비스에서 NetworkService 서비스를 다시 시작하십시오.
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;
}
TheirService의 SID 정보 :
C:\>sc showsid TheirService
NAME: TheirService
SERVICE SID: S-1-5-80-3034156332-2544749427-1608259134-1317875859-4063208518
C 번호에서 프로그램이면 MyService에서 TheirService을 시작하는 방법이 있나요?
편집 : 목표 - MyService 설치의 일부로 TheirService를 다시 시작하려고 할 수 있습니다.
TheirService를 수정할 수 있습니까? 그렇다면, 당신이 원하는 것을 얻을 수 있습니다. – Learner
@Cristi 불행히도. TheirService는 타사 서비스입니다. – amo