A friend sent a question today, as shown below:
Create a batch file. The function is to stop a service, perform file sorting, and start the service.
The command used here is:
SC stop servicename
SC start servicename
A friend's problem is that when the system executes batch processing, the system will continue to execute batch processing without waiting for the service to stop. This will cause subsequent file operations to fail, subsequent restart operations will also fail.
I haven't used SC commands before, so I searched for the command usage on Google. There is no problem with my friend's usage.
First, some suspect that the service is special, but the probability of this situation is relatively small. After all, the service is managed by the Windows system.
So I used "Stop Service" as the keyword to re-search and found familiar commands: net stop and Net start. These two commands can also stop and start the service.
As a result, a new batch file is created in your computer and the net command is used to manipulate the service.
In this way, the system can wait and everything is normal to achieve the goal.
After the net is changed to SC, an error occurs. The system continues to execute batch processing without waiting for the service to stop.
Although these two commands are similar, there are still slight differences. If you do not pay attention to them directly, it will be contrary to the purpose.