A Windows service is a background process that runs in the background of your Windows computer. It can run in the system tray, so it can be started and stopped at any time. You can create a Windows service programmatically using the ServiceController object or by using the Windows Services application. A Windows service does not have to start as a result of user action; it can also be started automatically when certain conditions are met, such as when the computer boots, or when an application is launched.
We can start/stop/restart any Windows service in two ways. One is to use of Windows graphical user interface, which is an easier option. Do you know that these services can also be managed via a command line interface? Yes, it can be. In this tutorial, we will discuss an option to manage a service state via the command-line interface.
How to Start/Stop a Windows Service using CLI
Windows Service Controller (sc) is a command line utility that communicates with Service Control Manager and services. It also provides you options to create/delete a Windows service and/or manage its state. You can also chagne the startup type of service.
Use the following commands to start or stop a Windows service:
- Start Service:
sc start ServiceName
- Stop Service:
sc stop ServiceName
You can also change the Windows service startup type using the sc
command. The following examples will help you to change service startup to manual or disable it.
- Set start type to manual:
sc config ServiceName start=manual
- Disable service:
sc config ServiceName start=disabled
Conclusion
This tutorial helped you to manage the Windows service state using the command line interface. Additionally provides you info about changing service startup type in the Windows system.
1 Comment
There is no restart option for sc