This article transferred from: http://www.cnblogs.com/hbccdf/p/managewindowsservicewithcmd.html
When it comes to managing Windows services, it's important to say that Windows services are managed through the command line, because the command line is a convenient and powerful tool, whether it's a system administrator or a programmatic way to invoke the cmd command.
Next, look at how to manage Windows services with the cmd command.
Main cmd command for managing Windows services
There should be a lot of commands for managing Windows services, but I've learned that there are two main commands: SC, net.
Said to be two cmd command, is actually the Windows System32 directory under the two execution program, because the environment variable path has system32 directory, so enter such a command, CMD will go to this command to find the corresponding execution program
Enumerate all Windows services and their details
With the SC query, you can enumerate all of the Windows services and their details:
sc query
View detailed information for a specified service
For example, see the details of the IISADMIN service
sc query IISAdmin
Start the Windows service
Starting a Windows service can be explained by two commands, the IISADMIN service, and the SC command
SC start IISAdmin
The other is the more commonly used NET command
net start IISAdmin
Stop the Windows service
You can also use the SC and net commands to stop Windows services
sc stop IISAdmin
net stop IISAdmin
Create a Windows service
command line to create a Windows service depends on the SC command,
Here's how the commands are used
Note that the format here, "=" is followed by an empty grid, or an error occurs.
Example:
SC Create services Binpath= "D:\code\c++\services\release\services.exe" type= own start= demand displayname= "service tes T "depend= Iisadmin/schedule
After you create the service, you can verify it through the service manager.
Remove Windows Services
SC Delete Services
Enumerate dependencies of Windows services
SC enumdepend IISAdmin
Additional functions of the SC command
All the functions of the SC command, as well as help information, can be entered SC directly in the CMD command window.
Summarize
Using the cmd command to manage the system can improve efficiency, although there is no user interface, but the function is powerful enough, commands are very rich, the use of programming can also reduce the complexity of the code.
Manage the two commands used by Windows services: SC, net.
Related information
DOTNETDR_ Recommended Information: sc command Help documentation
Series Links
Go to Windows Service Series--Create a Windows service
The registration and uninstallation of Windows Service series--debug, release version, and its rationale
Gaming Windows Service Family--no COM interface causes and solutions for Windows service startup failure
Go to Windows Service Series--Analysis of service operation and stop process
Go to Windows Service Series--windows Service Tips
Go to Windows service family--command-line management for Windows services
Play to Windows Service Series--windows service start time Out
Go to Windows service family--use boost.application to quickly build Windows services
Go to Windows Service family--add COM interfaces to Windows services
[Go] to the Windows service family--command-line management for Windows services