How to restart service using command prompt?

前端 未结 7 1768
一生所求
一生所求 2020-12-29 04:15

I want to restart Windows service using command prompt in [Icons] section using Inno Setup. Please help me to solve the problem.

7条回答
  •  春和景丽
    2020-12-29 05:11

    This is my code, to start/stop a Windows service using SC command. If the service fails to start/stop, it will print a log info. You can try it by Inno Setup.

    { start a service }
    Exec(ExpandConstant('{cmd}'), '/C sc start ServiceName', '',
         SW_HIDE, ewWaitUntilTerminated, ResultCode);
    Log('sc start ServiceName:'+SysErrorMessage(ResultCode));
    
    { stop a service }
    Exec(ExpandConstant('{cmd}'), '/C sc stop ServiceName', '',
         SW_HIDE, ewWaitUntilTerminated, ResultCode);
    Log('sc stop ServiceName:'+SysErrorMessage(ResultCode));
    

提交回复
热议问题