How to create service which restarts on crash

后端 未结 3 1421
耶瑟儿~
耶瑟儿~ 2021-02-13 21:06

I am creating a service using CreateService. The service will run again fine if it happens to crash and I would like to have Windows restart the service if it crashes. I know it

3条回答
  •  旧巷少年郎
    2021-02-13 21:17

    The answer above will give you the gist... but it wont compile.

    try:

    SERVICE_FAILURE_ACTIONS sfa;
    SC_ACTION actions;
    
    sfa.dwResetPeriod = INFINITE;
    sfa.lpCommand = NULL;
    sfa.lpRebootMsg = NULL;
    sfa.cActions = 1;
    sfa.lpsaActions = &actions;
    
    sfa.lpsaActions[0].Type = SC_ACTION_RESTART;
    sfa.lpsaActions[0].Delay = 5000; 
    
    ChangeServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, &sfa)
    

提交回复
热议问题