How can I restart a windows service using a .bat file? I am on windows server.
Asked
Active
Viewed 1.4e+01k times
1 Answers
84
net stop <your service> && net start <your service>
No net restart
, unfortunately.

Ry-
- 218,210
- 55
- 464
- 476
-
1I think you mean only one `&`. – vcsjones Dec 22 '11 at 17:26
-
@vcsjones: "Brilliant?" :D It's not really that different... but thanks. – Ry- Dec 22 '11 at 17:29
-
15To 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. – vcsjones Dec 22 '11 at 17:33
-
@vcsjones: Okay, well I didn't know that :) – Ry- Dec 22 '11 at 17:58
-
What is the difference if you put it on two separate lines ? – codea Dec 16 '13 at 16:05
-
1@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!) – Ry- Dec 16 '13 at 18:03
-
Why not just: `net stop
net start ` ? Just curious as to the meaning of the & there... -
6@PredragStojadinović: The `&&` means that if the `net stop` fails, the `net start` doesn’t run. – Ry- Feb 04 '15 at 18:02
-
how to handle errors that may happen? – Leonardo Galdioli Nov 21 '19 at 11:26