I have done a batch file that stop the services, delete files, install files, and start the services. till now it didn't have any trouble. but today it failed to install the files.
After a little search I have seen that the services are on stopping and not on stopped. I am using net stop "Service-Name" to stop the services.
How can I check when the services are stopped or wait for them to completely stop?
wmic service where name="Service-Name" get state
will show you whether a service is running or stopped. You can loop back to that command and use a ping to pause.Or if you prefer using
sc
to determine the state of a service:I'm not certain, but it's possible that a service could say "stopped" when it's actually "stopping", or "running" when it's actually "starting." If that's the case, then you might be better off checking whether a process exists in the process list. That can also be done using wmic:
wmic process where name="appname.exe" get name
or similar.