View Full Version : starting/stopping a service from command line


Charlie Hastings
02-26-2004, 03:04 PM
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

02-26-2004, 03:47 PM
"Charlie Hastings" <charlie.hastings@oico.on.ca> wrote in message
news:26b801c3fc79$c5d24500$a301280a@phx.gbl...
>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

02-26-2004, 03:47 PM
"Charlie Hastings" <charlie.hastings@oico.on.ca> wrote in message
news:26b801c3fc79$c5d24500$a301280a@phx.gbl...
>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

Phil Robyn [MVP]
02-26-2004, 07:09 PM
xpert@mailshell13.mailshell.com wrote:

> "Charlie Hastings" <charlie.hastings@oico.on.ca> wrote in message
> news:26b801c3fc79$c5d24500$a301280a@phx.gbl...
>
>>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

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

> 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
>
>


--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

Phil Robyn [MVP]
02-26-2004, 07:09 PM
xpert@mailshell13.mailshell.com wrote:

> "Charlie Hastings" <charlie.hastings@oico.on.ca> wrote in message
> news:26b801c3fc79$c5d24500$a301280a@phx.gbl...
>
>>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

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

> 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
>
>


--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

02-26-2004, 07:55 PM
"Phil Robyn [MVP]" <zipprobyn@berkeley.edu> wrote in message
news:O55dUwJ$DHA.1844@TK2MSFTNGP11.phx.gbl...
> xpert@mailshell13.mailshell.com wrote:
>
>> call sleep 10
>
> call :sleep 10

Oops! Thanks!

02-26-2004, 07:55 PM
"Phil Robyn [MVP]" <zipprobyn@berkeley.edu> wrote in message
news:O55dUwJ$DHA.1844@TK2MSFTNGP11.phx.gbl...
> xpert@mailshell13.mailshell.com wrote:
>
>> call sleep 10
>
> call :sleep 10

Oops! Thanks!