How to restart service using command prompt?

前端 未结 7 1777
一生所求
一生所求 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:16

    PowerShell features a Restart-Service cmdlet, which either starts or restarts the service as appropriate.

    The Restart-Service cmdlet sends a stop message and then a start message to the Windows Service Controller for a specified service. If a service was already stopped, it is started without notifying you of an error.

    You can specify the services by their service names or display names, or you can use the InputObject parameter to pass an object that represents each service that you want to restart.

    It is a little more foolproof than running two separate commands.

    The easiest way to use it just pass either the service name or the display name directly:

    Restart-Service 'Service Name'
    

    It can be used directly from the standard cmd prompt with a command like:

    powershell -command "Restart-Service 'Service Name'"
    

提交回复
热议问题