Restart a windows service from command line

Posted on 2012-12-28
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?
Question by:Roberto Madro R.
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
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.

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.
LVL 29

Assisted Solution

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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

LVL 76

Accepted Solution

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"

Author Closing Comment

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

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?

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 :)
LVL 29

Expert Comment

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"

Author Comment

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

Expert Comment

by:Alan Hardisty
ID: 38728406

Happy 2013 :)

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can’t disable NAT protocol in Windows Server 2012 3 83
AD account Auto logoff 1 37
Local admin account 3 40
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…
I had a question today where the user wanted to know how to delete an SSL Certificate, so I thought that I would quickly add this How to! Article for your reference. WHY WOULD YOU WANT TO DELETE A CERTIFICATE? 1. If an incorrect certificate was …
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
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…

749 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