Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Restart a windows service from command line

Posted on 2012-12-28
10
Medium Priority
?
1,056 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.
[X]
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
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 800 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 76

Accepted Solution

by:
Alan Hardisty earned 1200 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

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.

Question has a verified solution.

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

Scenario:  You do full backups to a internal hard drive in either product (SBS or Server 2008).  All goes well for a very long time.  One day, backups begin to fail with a message that the disk is full.  Your disk contains many, many more backups th…
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
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:…
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…

715 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