Solved

Restart a windows service from command line

Posted on 2012-12-28
10
1,049 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

To effectively work with Diskpart on a Server Core, it is necessary to write some small batch script's, because you can't execute diskpart in a remote powershell session. To get startet, place the Diskpart batch script's into a share on your loca…
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
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…

860 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