:: ------------------------------------- :: Start_Services.cmd :: :: - by Nick @ FoolishIT.com [Foolish IT LLC] :: - Official Download: https://download.foolishit.com/BatchFiles/Start_Services.cmd.txt :: :: Created: 7-18-08 :: Modified: 7-18-08 :: :: Batch script to start any number of :: services in any particular order. :: Runs on NT based OSes, but designed :: for and tested ONLY on Windows XP. :: "Seconds" are not quite that but close. :: ------------------------------------- @echo off&title Starting Windows Services...&set count=1 :: ========================= :: CONFIGURATION OPTIONS :: ========================= :: define the number of seconds you wish to wait until trying to start the service set delay=10 :: define the number of times to retry starting a service before failing set failnumber=3 :: to run additional passes at this script to ensure services you started stay that way. :: set morepasses equal to the number of times you want to run this batch subsequently :: set passdelay to xx seconds before you want to run the subsequent passes set morepasses=1 set passdelay=25 :: if you want to stop any services first, add them here :: each service name should be preceeded with call :stopsvc :: do not use display names but actual service names :: set stopdelay in seconds to wait for the service to stop set stopdelay=10 REM call :stopsvc D3Vme REM call :stopsvc D3odbcsv :startbat :: add each service name to start here in the order you want them started. :: each service name should be preceeded with call :startsvc :: do not use display names but actual service names call :startsvc D3Vme call :startsvc D3odbcsv :: ========================= :: END CONFIGURATION :: ========================= if not "%morepasses%"=="0" ( set nowaitmsg=1 echo.&echo Waiting for %passdelay% before running %morepasses% more passes...&echo.&echo. call :wait %passdelay% set /a morepasses=%morepasses% - 1 goto :startbat ) goto :end :stopsvc set svc=%1 echo Attempting to stop: %svc% sc stop %svc% set nowaitmsg=1 echo Delaying %stopdelay% seconds after attempting stop %svc%&echo. call :wait %stopdelay% goto :eof :startsvc set svc=%1 call :wait %delay% echo Attempting to start: %svc% sc query %svc% | find "STATE" | find "RUNNING" if errorlevel 1 ( sc start %svc% | find "FAILED" if errorlevel 0 ( echo Failed to start: %svc% &echo. set /a count=%count% + 1 if "%count%"=="%failnumber%" ( set count=1 echo. goto :eof ) else ( goto :startsvc ) ) else ( goto :startsvc ) ) else ( echo. call :wait %delay% ) goto :eof :wait if not "%nowaitmsg%"=="1" ( echo Delaying %delay% seconds before attempt to start: %svc% ) else ( set nowaitmsg=0 ) ping -n %1 127.0.0.1>nul goto :eof :end :: NOTE you can place "pause" here without the quotes to stop the batch and review what happened