Solved

Restart a windows service from command line

Posted on 2012-12-28
10
1,038 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:codedigger
  • 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:codedigger
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 28

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
 
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:codedigger
ID: 38728379
EE pros come through again, many thanks, worked like charm.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:codedigger
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 28

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:codedigger
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Normally after a failure of Domain Controller, when promoting new DC the DC is renamed, we will discuss the options in Dcpromo to re-create the DC with the same name. Scenario: You are a small IT shop with two Domain Controllers (Domain Contr…
If you migrate a Terminal Server licenses server inside the 2008 server family, you can takte advantage of the build-in migration tool. If you like to migrate an older 2003 Server (and the installed client CALs) to a 2008 R2 server for example, you …
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now