132

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?

closed as off topic by Will May 27 '13 at 15:41

Questions on Stack Overflow are expected to relate to programming within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 3 '13 at 21:23
202

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>
  • 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 9 '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: stackoverflow.com/questions/1405372/… – Eric Falsken Jun 11 '10 at 20:34
  • 6
    On Powershell you need to use sc.exe \\machine stop <service>. Otherwise, I think, sc refers to a different command. – CJBrew Jun 3 '11 at 15:11
  • 4
    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
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.

  • 1
    Oops, didn't see the "command line" requirement. – Ryan Duffield Oct 9 '08 at 15:45
  • 7
    What port(s) would I need to unblock on my server? – The Muffin Man Apr 22 '14 at 16:33
  • 2
    This is gold. I have always been accessing servers remotely to handle services. Now with this I can have a list of different servers within the same console. – Alan Jul 19 '17 at 14:03
9

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

  • PSService is useful as well. There's a lot of power in those tools. – Brad Bruce Jan 31 '14 at 4:18
7

Using command line, you can do this:

AT \\computername time "NET STOP servicename"
AT \\computername time "NET START servicename"
  • 5
    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: stackoverflow.com/questions/1405372/… – 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.

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).

  • 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.

  • 2
    Telnet is most definitely unencrypted. – Josh Kodroff May 20 '09 at 15:21
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.