Unable to stop and start windows services

(imported topic written by SystemAdmin)

I need to stop and then start a windows service after changing an applications configuration file, but I think the service is not completely down when I try to start it after stopping, resulting in failure to start

//Fixlet

wait cmd.exe /C net stop “Service name”

wait cmd.exe /C net start “Service name”

Is there a better way or some command to use that can wait until it’s stopped to initiate a start?

(imported comment written by SystemAdmin)

I’m not 100% sure but there may be some other services that need to stop/start with a service. There is a fixlet in BESSupport that is for restarting services (fixlet 447) which has some extra parameters.

(imported comment written by SystemAdmin)

You may be able to use a “pause while()” command to keep from moving on to the next step while the service is still running. If it is reporting that it has stopped running too quickly, then you could also add a “pause while()” command to pause for 30 seconds or something like that.

(imported comment written by SystemAdmin)

if {exists running application whose (name of it as lowercase = “iexplore.exe”)}

waithidden taskkill /F /T /IM iexplore.exe

pause while {exists running application “iexplore.exe”}

endif

if {exists running application whose (name of it as lowercase = “firefox.exe”)}

waithidden taskkill /F /T /IM firefox.exe

pause while {exists running application “firefox.exe”}

endif

if {exists running application whose (name of it as lowercase = “chrome.exe”)}

waithidden taskkill /F /T /IM chrome.exe

pause while {exists running application “chrome.exe”}

endif

(imported comment written by SystemAdmin)

More examples:

// The following is my attempt to deal with explorer.exe closing at the finish of installation.

continue if{exists current user}

//pause for 15 seconds

parameter “start_0” = “{now}”

pause while {now < ( (( parameter “start_0” of action ) as time ) + 15* second)}

//do some stuff after 15 seconds

if {(exists running applications whose (name of it as lowercase = “explorer.exe”))}

parameter “start_1”="{now}"

pause while {(exists running applications whose (name of it as lowercase = “explorer.exe”)) AND (now-time (parameter “start_1”) < 360*second)}

endif

//continue if {not (exists running applications whose (name of it as lowercase = “explorer.exe”))}

// reopen explorer.exe as current user.

rundetached __Download\RunAsCurrentUser.exe C:\Windows\explorer.exe