141

Sometimes while debugging, I need to restart a service on a remote machine. Currently, I'm doing this via Remote Desktop. How can it be done from the command line on my local machine?

Josh Kodroff
  • 25,181
  • 26
  • 90
  • 147
  • 1
    None of these answers explain how to do the remote start, while handling the user permissions required to execute the service call. – djangofan Jun 03 '13 at 21:23

8 Answers8

213

You can use the services console, clicking on the left hand side and then selecting the "Connect to another computer" option in the Action menu.

If you wish to use the command line only, you can use

sc \\machine stop <service>
Vinko Vrsalovic
  • 244,143
  • 49
  • 315
  • 361
  • 1
    Works perfectly from cmd.exe. Does not work in PowerShell, probably because of the \\, error follows: Set-Content : A parameter cannot be found that matches parameter name '[the name of the service]'. Only minor drawback is that it returns you to the command line before the operation is finished. – Josh Kodroff Oct 09 '08 at 22:23
  • 4
    since the sc command works asyncronously, if you need to script a service restart, take a look at the batch scripts I posted here: http://stackoverflow.com/questions/1405372/stopping-starting-a-remote-windows-service-and-waiting-for-it-to-open-close – Eric Falsken Jun 11 '10 at 20:34
  • 6
    On Powershell you need to use `sc.exe \\machine stop `. Otherwise, I think, sc refers to a different command. – CJBrew Jun 03 '11 at 15:11
  • 5
    What is the minimum set of permissions required for a user to start a specific remote service on the remote computer? – huseyint Jun 17 '11 at 14:42
  • +1 this works with no hassle in powershell, contrary to things like Invoke-Command \\remote_machine { Start-Service ... } (which requires Windows Remote Management configured on remote_machine), and it wins over PsTools in that sc.exe comes by default with Windows installation – hello_earth Jul 19 '11 at 10:15
  • On PowerShell you can simply do it with Restart-Service commandlet: `Get-Service W3SVC -computer myserver | Restart-Service` – Jan Remunda Mar 18 '14 at 11:09
  • @JanRemunda Any full source code sample in Powershell ? – Kiquenet Jul 24 '14 at 12:44
  • That is full sample. With cmdlet get-service you resolve w3svc service object on computer "myserver" and pipe it with | to restart-service cmdlet. – Jan Remunda Jul 24 '14 at 12:49
  • +1 Just as a side note, in case you have to do this from a non-admin account you have to grant permissions to that user as described in the answer here: https://social.technet.microsoft.com/Forums/windowsserver/en-US/e9d3a8d3-5301-4961-96be-99f586c6fc1c/using-ad-to-allow-a-user-to-startstop-a-service?forum=winserverDS – paulroho Sep 15 '16 at 14:06
41

You can use mmc:

  1. Start / Run. Type "mmc".
  2. File / Add/Remove Snap-in... Click "Add..."
  3. Find "Services" and click "Add"
  4. Select "Another computer:" and type the host name / IP address of the remote machine. Click Finish, Close, etc.

At that point you will be able to manage services as if they were on your local machine.

Ryan Duffield
  • 16,649
  • 6
  • 36
  • 38
9

You can use System Internals PSEXEC command to remotely execute a net stop yourservice, then net start yourservice

Philibert Perusse
  • 3,656
  • 5
  • 22
  • 25
6

Using command line, you can do this:

AT \\computername time "NET STOP servicename"
AT \\computername time "NET START servicename"
Andrew Moore
  • 87,539
  • 30
  • 158
  • 173
  • 6
    to make it clear, the "AT" command uses the windows scheduler to schedule a command. it's overkill for scripting a number of remote commands and doesn't guarantee execution order or command completion before the next command. The SC command is much better for this. Take a look at the batch scripts I posted in this question: http://stackoverflow.com/questions/1405372/stopping-starting-a-remote-windows-service-and-waiting-for-it-to-open-close – Eric Falsken Jun 11 '10 at 20:33
1

I would suggest you to have a look at RSHD

You do not need to bother for a client, Windows has it by default.

tafa
  • 6,858
  • 3
  • 33
  • 38
0

Well, if you have Visual Studio (I know it's in 2005, not sure about earlier versions though), you can add the remote machine to your "Server Explorer" tag. At that point, you'll have access to the SERVICES that are running, or can be ran, from that machine (as well as event logs, and queues, and a couple other interesting things).

Stephen Wrighton
  • 33,316
  • 6
  • 63
  • 84
  • Bizarrely, this works in VS2005 but NOT in VS2008. You can still BROWSE the services but no longer start or stop them directly. In lieu of this, you can right-click the Services node and start Service Manager for that host. – Peter Wone Jan 31 '09 at 14:20
0

One way would be to enable telnet server on the machin you want to control services on (add/remove windows components)

Open dos prompt
Type telnet yourmachineip/name
Log on
type net start &serviceName* e.g. w3svc

This will start IIS or you can use net stop to stop a service.

Depending on your setup you need to look at a way of securing the telnet connection as I think its unencrypted.

alexmac
  • 4,125
  • 3
  • 27
  • 32
0

Several good solutions here. If you're still on Win2K and can't install anything on the remote computer, this also works:

Open the Computer Management Console (right click My Computer, choose Manage; open from Administrative Tools in the Start Menu; or open from the MMC using the snap-in).

Right click on your computer name and choose "Connect to Remote Computer"

Put in the computer name and credentials and you have full access to many admin functions including the services control panel.