There are two ways to execute CMD directives in C + +:
Method 1:system ("Calc");
Method 2:winexec ("Calc", Sw_normal); Related reminders: 1. You do not need to add a header file when using these two functions, because the system function is declared in Stdlib.h, and the WinExec function is declared in WinBase.h. 2. Be aware of the differences between the two methods, as shown below, when the system function executes, it does not sequentially execute the next code, but stays on the system statement until the cmd instruction is executed; When the WinExec function executes, the next code is executed sequentially. Whether or not its cmd command is executed;
To start a service program or shut down a service program with a DOS command:
1. Use the Net start/stop command to start the service program or shut down the service program
net start ServiceName (service name)
net stop ServiceName (service name)
If the service name has spaces, you need to enclose them in double quotation marks. Like what:
C:\>net start "Windows firewall/internet Connection Sharing (ICS)"
The Windows firewall/internet Connection Sharing (ICS) service is starting.
The Windows firewall/internet Connection Sharing (ICS) service has started successfully.
C:\>net Stop "Windows firewall/internet Connection Sharing (ICS)"
The Windows firewall/internet Connection Sharing (ICS) service has stopped successfully.
2. Start the service program or close the service program using the SC command
SC start ServiceName (service name)
sc stop ServiceName (service name)
Like what:
C:\>SC Start APACHE_PN
Service_name:apache_pn
Type:10 win32_own_process
State:2 start_pending
(Not_stoppable,not_pausable,ignores_shutdown)
win32_exit_code:0 (0x0)
service_exit_code:0 (0x0)
checkpoint:0x0
Wait_hint:0x7d0
pid:8756
FLAGS:
C:\>SC Stop APACHE_PN
Service_name:apache_pn
Type:10 win32_own_process
State:3 stop_pending
(Not_stoppable,not_pausable,ignores_shutdown)
win32_exit_code:0 (0x0)
service_exit_code:0 (0x0)
checkpoint:0x4
wait_hint:0x7530
Report:
CMD net start service tip system error 5 What to do if access is denied?
Two cases:
1, no administrator rights?
2, the service uses the port is occupied, such as the Web service port 80 port, may be Thunderbolt, QQ cyclone Occupy (can be adjusted).
Use batch processing to shut down and disable a service under XP
C:\>SC config wuauserv start= disabled
[SC] Changeserviceconfig SUCCESS
Wuauserv the name of the service that is automatically updated for Windows.
Using SC to install a service Telnet
SC create tlntsvr binpath= "D:\WINDOWS\system32\tlntsvr.exe" displayname= "Telnet"
[SC] OpenService FAILED 1060:
There are no installed services present
SC Common Command parameters
SC Create creates a service
SC Delete Deletes a service
sc query Service
sc config Configuration service
sc stop shutdown Service
SC Start Open Service
SC Pause Pause Service
SC Introduction
SC is a console program that communicates with the NT Service controller, which can query and modify the database of installed services.
Syntax: SC [command] [service name] ..., the option is "\\ServerName" in the form.
The main commands include: Query,config,qc,delete,create,getdisplayname,getkeyname,enumdepend and so on.
C + + call cmd command