프로젝트 C#의 WiX 설치에 대한 사용자 지정 작업에서 서비스를 시작하려고합니다.WiX 사용자 지정 작업에서 서비스를 시작할 수 없습니다.
[CustomAction]
public static ActionResult StopService(Session session)
{
ServiceController MyService = null;
try
{
MyService = new ServiceController("MyService");
if (MyService != null) &&(MyService.Status != ServiceControllerStatus.Stopped))
{
MyService.Stop();
MyService.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 2, 0));
}
session.Log("Stop service");
}
catch (Exception ex)
{
session.Log(ex.ToString());
}
}
을하지만 상태 (MyService.Status
) 취득하려고하면 예외가있다 :
은 처음에는 서비스가 시작되었는지 확인
System.InvalidOperationException를 : 불가능 디부 ouvrir을 르 서비스 MyService sur l' ordinateur '.'. ---> System.ComponentModel.Win32Exception : 특정 서비스를 다시 시작하십시오. 큐 서비스를 설치하십시오. --- 파일 추적을 추적하십시오. d' exception interne --- System.ServiceProcess.ServiceController. CustomAction.CustomActions.StopService à System.ServiceProcess.ServiceController.get_Status() (세션 세션)
번역 à System.ServiceProcess.ServiceController.GenerateStatus() à GetServiceHandle (INT32 desiredAccess) : "할 수 없음 이 컴퓨터의 MyService 열기 -> 지정한 서비스가 설치된 서비스로 존재하지 않습니다.
서비스가 설치되어 있는지 어떻게 확인할 수 있습니까? (MyService가 null이 아닙니다.)