P
P
PoliceMemos2020-01-30 14:20:58
PowerShell
PoliceMemos, 2020-01-30 14:20:58

How to write a script so that it waits for the service to stop?

There is a server on which a service sometimes hangs, but with its restart, you have to restart a number of services in a certain sequence. I decided to write a .bat script like this:
Net stop "CSTA Mux"
Net stop "TapiSrv"
Net stop "ProstieZvonkiPanasonicService"
Net stop "TAPIZWE"
Net start "CSTA Mux"
Net start "TapiSrv"
Net start "ProstieZvonkiPanasonicService"
Net start "TAPIZWE "


But the problem is that script execution does not wait for the service to stop or start, but executes a trace. line due to which ProstieZvonkiPanasonicService does not have time to stop and is already receiving a Start command. As a result, it does not work correctly.

How can I write a script to trace. the action was performed only upon successful completion of the previous one?

Options with time and inserting a pause of 10 seconds will not help, because sometimes "ProstieZvonkiPanasonicService" stops in 10 seconds, and sometimes in 120 seconds.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-01-30
@PoliceMemos

Use powershell cmdlets. They are waiting.

The PowerShell cmdlets Stop-Service and Start-Service will wait until the services are fully stopped and started respectively.

https://superuser.com/questions/396906/is-there-a-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question