The Core Technologies Blog

Our Software // Windows Services // 24×7 Operation


Q&A: How do I Restart a Windows Service on a Remote Computer?

How do I restart a Windows Service on a remote computer?
  What’s the best way to restart a Windows Service remotely from our central domain server?

— Sylvia W.

Hi Sylvia.

We know of at least five ways to restart a Windows Service on a remote machine. Let’s review each method, focusing on the pros and cons to help you select the approach that best fits your situation.

Note: If any of the methods fail with security related errors (such as “access denied”), you may need to update security settings on the remote machine.

Method #1: Use the Services application to connect to the remote PC

Did you know that the Services application works with remote computers? For some reason, Microsoft buried that feature in the interface, making it very easy to miss!

To view services on another computer:

  1. Start the Services application

  2. In the left panel, right-click Services (Local) and select Connect to another computer from the menu:

    Services: Connect to another computer
  3. In the Select Computer window, specify the computer hosting your Windows Service:

    Specify the remote computer
  4. Click OK to access the remote PC

  5. The Services application should refresh to list the services on your other computer. From there, you can start or stop any service you like:

    Services on the remote computer

If that didn’t work, you may need to update your security settings.

Pros

  • Services is a standard utility that is available on every Windows computer.

  • Services is very easy to use.

  • Besides starting or stopping the service, you can also update the service’s properties. For example, you can disable the service, setup failure actions or change the log on account.

Cons

  • Working with Services is interactive. You (or your tech) must log in, start Services, connect to the remote PC and start the service. You can’t call Services from a batch file. As a result, this approach is not suitable for non-interactive situations.

Method #2: Run SC with the “server” command line parameter

If you’re comfortable working from the command prompt, the SC utility should be in your toolbox.

To stop a Windows Service on another machine, run:

SC \\<SERVER-NAME> STOP <SERVICE-NAME>

For example, to stop the Spooler service on our file server (named “ctc-file-server”), we run:

SC \\ctc-file-server STOP Spooler

SC stopping a remote service

Be sure to run SC from an elevated command prompt — run as an administrator. If not, the command could fail because of insufficient permissions.

Pros

  • SC is a standard utility that is available on every Windows computer.

  • With SC, you can easily start or stop a service.

  • You can call SC from a batch file, which makes it suitable for non-interactive scenarios.

  • SC can do much more than start or stop a service. You can use it to change a service’s properties as well. In fact, it supports many more settings than the Services application does. Run SC /? to see the full set of options available.

Cons

  • When starting or stopping a service, SC simply makes a request and exits. It will not wait for the service to transition to the desired state. Unfortunately, that behavior can cause complications in batch files. For example, if you call “SC STOP” immediately followed by “SC START”, the start command will fail if the service takes a few seconds to stop.

Method #3: Install and run Microsoft’s PsService

If you’re familiar with the amazing (and free) tools from Microsoft’s SysInternals group, you should definitely check out their PsService utility.

Like SC, PsService allows you to start, stop or restart your service from the command line. And importantly, PsService works with remote computers.

In fact, PsService offers a rich set of command line options. Run PsService /? to see them:

PsService command line help

Look closely and you’ll see that PsService offers one important capability that neither SC nor Services does — the ability to specify the account to use on the remote computer. That feature comes in handy if your account doesn’t have enough rights or if you want to use a specific account to control the service.

For example, to start the Spooler service on our “ctc-file-server” computer, we run:

PsService \\ctc-file-server start Spooler

PsService starting a remote service

Pros

  • PsService is safe, free, reliable and endorsed by Microsoft.

  • With PsService, you can easily start or stop a service.

  • You can call PsService from a batch file, which makes it suitable for non-interactive scenarios.

  • With PsService, you can specify the username and password of an administrative account on the remote PC. As a result, your account doesn’t need to have administrative rights on the remote computer.

Cons

  • PsService does not come pre-installed on your computer. You will have to download and install/unzip the PSTools suite to use PsService. This may be an issue if you are operating in a “locked down” environment where adding new software is difficult.

  • When starting or stopping a service, PsService simply makes a request and exits. It will not wait for the service to transition to the desired state. Unfortunately, that behavior can cause complications in batch files. For example, if you call “PsService stop” immediately followed by “PsService start”, the start command will fail if the service takes a few seconds to stop.

Method #4: Use Microsoft’s PsExec to run NET

PsExec is another powerful tool in the SysInternals arsenal. It allows you to run arbitrary commands on a remote computer.

Running the NET command with PsExec produces a command that will start or stop your service and wait for it to complete. That may be an important improvement over SC and PsService, which simply put in a request and exit.

For example, this command stops the Spooler service on our “ctc-file-server” computer:

PsExec \\ctc-file-server NET STOP SPOOLER

Stopping a remote service with PSEXEC and NET

Pros

  • PsExec is safe, free, reliable and endorsed by Microsoft.

  • With PsExec and NET, you can easily start or stop a service.

  • You can call PsExec from a batch file, which makes it suitable for non-interactive scenarios.

  • With PsExec, you can specify the username and password of an administrative account on the remote PC. As a result, your account doesn’t need to have administrative rights on the remote computer.

  • PsExec with NET will wait for your service to start or stop before returning.

Cons

  • PsExec does not come pre-installed on your computer. You will have to download and install/unzip the PSTools suite to use PsExec. This may be an issue if you are operating in a “locked down” environment where adding new software is difficult.

  • NET waits up to 30 seconds for the service to start or stop. That may not be enough time for a service that takes a long time to transition.

Method #5: Use PsExec to run ServicePilot

If your service takes a while to start or stop, you may want to use our free ServicePilot utility instead of NET. With ServicePilot, you are not limited to a 30-second timeout.

ServicePilot is better than NET in other ways too. For example, ServicePilot can restart a service in one operation (instead of issuing a stop followed by a start) or forcibly terminate a misbehaving service.

This command uses ServicePilot to start the Spooler service on our “ctc-file-server” computer:

PsExec \\ctc-file-server C:\Apps\ServicePilot.exe -start Spooler

Stopping a remote service with PSEXEC and NET

Note that the command above assumes that the ServicePilot executable is available on the remote machine. If that is not the case and you only have ServicePilot on the local machine, you must instruct PsExec to copy the executable to the remote PC by specifying the -c parameter. Here is what that command looks like:

PsExec \\ctc-file-server -c "C:\Apps\ServicePilot.exe" ServicePilot.exe -start Spooler

Even though it’s less efficient, having PsExec copy the executable each time might be the better option for occasional (and unplanned) use cases.

Pros

  • ServicePilot is safe and free.

  • With PsExec and ServicePilot, you can easily start or stop a service.

  • You can call PsExec from a batch file, which makes it suitable for non-interactive scenarios.

  • With PsExec, you can specify the username and password of an administrative account on the remote PC. As a result, your account doesn’t need to have administrative rights on the remote computer.

  • PsExec with ServicePilot will wait for your service to start or stop before returning.

Cons

  • Neither PsExec nor ServicePilot come pre-installed on your computer. You will have to download them. This may be an issue if you are operating in a “locked down” environment where adding new software is difficult.

That’s it. Hopefully one of these five methods works for you.


Appendix: Update security settings to access your remote service

Windows does a great job of locking down services. As such, you may have to relax the rules if you want to start or stop a service remotely.

Ensure that your account has sufficient rights on the remote machine

Are you sure that your Windows account can update the service?

Can you log in to the remote machine and start or stop the service?

If not, you’re probably missing permissions. You may have to:

  • Make your account an administrator on the remote computer. By default, only administrators can manipulate Windows Services.

  • Give your account permission to access the service. Log in to the remote computer and use our free Service Security Editor utility to adjust the service’s permissions:

    Update service permissions

Disable UAC remote restrictions

If you are not in a domain, your requests may be blocked by User Account Control (UAC) remote restrictions. Essentially, to enforce the principle of least privilege, Windows may not respect your administrative rights on the remote computer.

But there is a simple fix. You can disable UAC remote restrictions by updating the registry as follows:

  1. Open the Windows Registry Editor (regedit)

  2. Navigate to this key:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System

    Regedit: Windows System Policies
  3. Look on the right side. If there is no value named LocalAccountTokenFilterPolicy, create it by selecting Edit > New > DWORD (32-Bit) Value and naming it.

  4. On the right side, right-click LocalAccountTokenFilterPolicy and select Modify. Enter a value of 1:

    Regedit: Update LocalAccountTokenFilterPolicy
  5. Click OK to save your changes.

  6. Close Registry Editor


Posted in Windows Services | Tagged , , , , , , , , | Leave a comment

Leave a Reply

Your email address will not be published.