Batch file to restart a service. Windows
131,858
net stop <your service> && net start <your service>
No net restart
, unfortunately.
Comments
-
Tony over 4 years
How can I restart a windows service using a .bat file? I am on windows server.
-
vcsjones over 12 yearsI think you mean only one
&
. -
vcsjones over 12 yearsHm. I didn't know that worked. Brilliant.
-
Ry- over 12 years@vcsjones: "Brilliant?" :D It's not really that different... but thanks.
-
vcsjones over 12 yearsTo me it is interesting, it short circuits. I never considered that a batch script could do that. The right doesn't execute if the %errorlevel% of the left is none zero. If you use a single
&
, then both execute regardless of the result of the left. -
Ry- over 12 years@vcsjones: Okay, well I didn't know that :)
-
codea over 10 yearsWhat is the difference if you put it on two separate lines ?
-
Ry- over 10 years@codea: If you put it on two separate lines, if the first one fails, the second one will still go through. (And then it’s also not a one-liner!)
-
Predrag Stojadinović over 9 yearsWhy not just:
net stop <your service> <newline> net start <your service>
? Just curious as to the meaning of the & there... -
Ry- over 9 years@PredragStojadinović: The
&&
means that if thenet stop
fails, thenet start
doesn’t run. -
Predrag Stojadinović over 9 years@minitech: Awesome. Thanks.
-
Leonardo Galdioli over 4 yearshow to handle errors that may happen?