Solved

Restart a windows service from command line

Posted on 2012-12-28
10
1,044 Views
Last Modified: 2012-12-28
I'm familiar with the "net start", "net stop", etc. to manage a service in windows, but do you know of a "restart" command?
0
Comment
Question by:Roberto Madro R.
  • 4
  • 4
  • 2
10 Comments
 
LVL 76

Expert Comment

by:Alan Hardisty
ID: 38728339
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
0
 

Author Comment

by:Roberto Madro R.
ID: 38728346
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.
0
 
LVL 29

Assisted Solution

by:becraig
becraig earned 200 total points
ID: 38728354
You can script this
Step 1 find the name of the service and query svcname
take the PID from the step and then run “taskkill /PID xxxx /F”

you can write this into a simple bat file and pass in the service name
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 76

Accepted Solution

by:
Alan Hardisty earned 300 total points
ID: 38728364
You should be able to use the taskkill command to terminate a hung service:

So combined:

net stop "ServiceName"
taskkill /f /fi "services eq ServiceName"
net start "ServiceName"
0
 

Author Closing Comment

by:Roberto Madro R.
ID: 38728379
EE pros come through again, many thanks, worked like charm.
0
 

Author Comment

by:Roberto Madro R.
ID: 38728385
Can I follow up?  Is that allowed.?  if so, how can execute this against a remote server?

Thx
0
 
LVL 76

Expert Comment

by:Alan Hardisty
ID: 38728401
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 :)
0
 
LVL 29

Expert Comment

by:becraig
ID: 38728402
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"
0
 

Author Comment

by:Roberto Madro R.
ID: 38728404
You mighty kind Alan, Many thanks to both of you & happy new year.
0
 
LVL 76

Expert Comment

by:Alan Hardisty
ID: 38728406
Anytime.

Happy 2013 :)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
A safe way to clean winsxs folder from your windows server 2008 R2 editions
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question