starting/stopping a service from command line

  • Thread starter Thread starter Charlie Hastings
  • Start date Start date
C

Charlie Hastings

I know nothing about scripting, but I would like to run a
scheduled script that will stop and start a particular
service.

Can I do this? If yes, how?

Thanks
 
Charlie Hastings said:
I know nothing about scripting, but I would like to run a
scheduled script that will stop and start a particular
service.

Can I do this? If yes, how?

Run something like this from the task scheduler:

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
net stop ServiceName
call sleep 10
net start ServiceName
goto :EOF

:sleep
:: sleep for x number of seconds
ping -n %1 127.0.0.1 > NUL 2>&1
goto :EOF
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Where ServiceName is the name of the service you want to start and stop,
like NTPTime.
If you have a software firewall then it might be better to use sleep.exe
from the resource kit or mine here,
http://www.paulsadowski.com/WSH/cmdprogs.htm
 
Run something like this from the task scheduler:

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
net stop ServiceName
call sleep 10

call :sleep 10

net start ServiceName
goto :EOF

:sleep
:: sleep for x number of seconds

:: sleep for x number of seconds - 1
:: if you really want to sleep for x number of seconds,
:: you must add 1 to the parameter
 
Back
Top