Avatar of Roberto Madro R.
Roberto Madro R.
Flag for United States of America asked on

Restart a windows service from command line

I'm familiar with the "net start", "net stop", etc. to manage a service in windows, but do you know of a "restart" command?
Windows Server 2008

Avatar of undefined
Last Comment
Alan Hardisty

8/22/2022 - Mon
Alan Hardisty

You can combine the two into one command to restart a service:

net stop "Service Name" && net start "Service Name"

Not aware of a restart command line command.

http://technet.microsoft.com/en-us/library/cc736564(v=ws.10).aspx
Roberto Madro R.

ASKER
On a service that's behaving normally your suggestion works great, my problem is that I have a 3rd party app that has a deffective service that hangs between start and stop, so I can only restart (as the only logical step remaining), I can't stop the service because according to its status it's already "stopped" or sort-of stopped, and I can't restart it because it's already "sarted" or sort-of started, that's why I'm left with the "Restart" option. And I'm thinking since windows offers the "Restart" command, it must be known / available for use from the command line.
SOLUTION
becraig

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Alan Hardisty

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Roberto Madro R.

ASKER
EE pros come through again, many thanks, worked like charm.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Roberto Madro R.

ASKER
Can I follow up?  Is that allowed.?  if so, how can execute this against a remote server?

Thx
Alan Hardisty

Use the following:

sc \\computername stop "ServiceName"
taskkill /s computername /f /fi "services eq ServiceName"
sc \\computername start "ServiceName"

Technically you should only ask one question per thread, but it's the season of goodwill :)
becraig

Using Alan's method you can use psexec

psexec \\servername /cmd /c net stop "ServiceName"
psexec \\servername /cmd /c taskkill /f /fi "services eq ServiceName"
psexec \\servername /cmd /c net start "ServiceName"
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Roberto Madro R.

ASKER
You mighty kind Alan, Many thanks to both of you & happy new year.
Alan Hardisty

Anytime.

Happy 2013 :)