The Core Technologies Blog

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


Essential Tools for Windows Services: The NET Command

If you manage Windows Services and are comfortable working from the command line, then the Windows NET.EXE command should be in your toolkit. Use it to easily start, stop, pause or restart any service from an elevated DOS prompt, or in a convenient script/batch file.

Using NET to stop a Windows Service

To stop a service, run:

net stop <Service-Name>

where <Service-Name> is the name of the service. Be sure to enclose it in quotes if it contains a space!

For example, to stop the Print Spooler service (named “Spooler”), run:

net stop Spooler

Here is what it looks like on our Windows Server 2016 computer:

NET: Stopping the Print Spooler Service

Notice that the NET command will wait for the service to stop before continuing. The only exception is when the service is unresponsive or takes more than 30 seconds to comply.

Starting a Windows Service with NET

To start an idle Windows Service, run:

net start <Service-Name>

If all goes well, your service (and any other service it depends on to operate) will be started after a few seconds:


NET: Start the Print Spooler Service

How to Restart a Windows Service with NET.EXE

To restart a service, say from a batch file, chain the “net stop” and “net start” commands together like this:

net stop <Service-Name>
net start <Service-Name>

NET will also Pause and Resume Windows Services

Not all services support pause and resume, but if you have one that does, NET can come in handy there as well.

To pause a service, type:

net pause <Service-Name>

To resume a paused service, run:

net continue <Service-Name>

Posted in Windows Services | Tagged , , | 20 Comments

20 Responses to Essential Tools for Windows Services: The NET Command

  1. Art Wilmoth says:

    On using the NET command in a batch to restart I recommend adding time for the services to react. I’ve done this for one of my services that tends to hang. See below;

    @ECHO.
    @ECHO Stopping services, please wait for 10 seconds…

    @ECHO OFF
    REM Stop Service

    NET STOP ServiceNameHere

    REM The following is a timer to allow for server RAM to clear after the service has stopped
    REM Use the numerical value within the ‘timeout’ command line to control how many seconds the pause will be.

    TIMEOUT /t 10 /NOBREAK
    ECHO.

    NET START ServiceNameHere

    PAUSE

    EXIT

  2. Sunny says:

    I have a query if I need to start the multiple services and those service is taking more than 30 seconds to come up then how can i achieve that as currently its failing with error “‘net’ timed out after 30 seconds”.

    Appreciate your early response. thanks

    • ctcadmin says:

      Hi. We recommend creating a batch file that uses the SC command to stop the service and check on it later.

      To stop the service with SC, use:
      SC STOP servicename

      To check if a service was successfully stopped (after you wait for longer than 30 seconds), use the following command:
      SC QUERY servicename | FIND “STATE” | FIND “STOPPED”

      It will set the %ERRORLEVEL% variable to 1 if the service is not in the Stopped state.

      Click here for some info on SC.

  3. Sean Sparks says:

    I need a script to test users ability to start a service. Multiple users on multiple servers. Can i do that with SC or NET commands?

  4. ctcadmin says:

    Though its results may be tricky to decipher, you can use the “SC SDSHOW” command to see the service’s security descriptor.

    If you don’t mind attempting to start the service, you can also use NET START and search for errors, as shown in the example on this page.

  5. Ajay says:

    sir net stop telnet how to use this cmd

  6. Brandon Hutson says:

    Make note that if the service name is two words or more you must enclose the name with quotation marks. Took me a while to find that!

  7. I want to restart services on multiple windows servers and it take around 1 minute to be stopped . I tried to use NET STOP but its not waiting and just executed next command to start . Can someone please help me with the exact script which i can use to restart services on multiple servers.

  8. ctcadmin says:

    NET STOP will only wait for about 30 seconds for the service to stop. If a service takes longer than a few seconds, NET will fail with an “Unable to wait” message.

    Unfortunately there is no way to tell NET STOP to “wait longer”. And the SC utility won’t be any help as it doesn’t even attempt to wait.

    We recommend using the “safeServiceStop.bat” (or “safeServiceRestart.bat”) batch file described in this article.

    Save the batch file to your file system and call it from your existing batch file. Note that you should add “localhost” when calling the new batch file. For example, to stop a service called “Spooler”, use

    safeServiceStop localhost Spooler

    Note that the recommended solution will wait indefinitely for the service to stop. If the service never stops, your script will hang.

     


     

    UPDATE 8/27/2018: We have created a free command line utility (called ServicePilot) that will wait for as long as you like when stopping the service. You can use it instead of the batch file recommended above — it’s a much simpler alternative.

    Be sure to specify an appropriate value for the “-wait” flag when using ServicePilot. For example, to stop the Spooler service when it may take 5 minutes (300 seconds) to comply, use:

    ServicePilot -wait 300 Spooler

    Note that the service will be forcibly terminated if it doesn’t stop gracefully in the given time frame.

  9. Jorge says:

    Stopd service Tobii. It does not accept the Net Start command, and Sc start, says that the command is invalid, service name (Tobii Service)

  10. ctcadmin says:

    What command are you using to stop Tobii?

    Make sure you are specifying the name of the service. And enclose the name in quotes if it contains a space!

    • Jorge says:

      It was right, I was putting the name without (“) hence it was wrong, now it worked out ,,, Net start” Tobii Service “

  11. Martin Hydén says:

    If I use net stop and and net start on a special service that have stoped working correct it doesn’t help, it still working incorrect.
    But when restart the same service from services.msc it reset the service correct. What is the difference?

    (service name is in one word, so not the quotes problem..)

  12. ctcadmin says:

    Does NET STOP/START print any error messages to the console? Perhaps it is failing and not actually stopping/starting the service.

    A common problem: NET STOP/START will fail if you are not running with sufficient rights. Make sure that you are working in an elevated prompt (started with “Run as Administrator”).

    • Martin Hydén says:

      Thank you. No error messages, it just says that the servicie is stopped. And yes I run it elevated.
      I will try timeout from the first comment next time i’m at the actual computer.

  13. Joseph Sharp says:

    A really common problem when the net or SC commands and some custom services is that you have to specifiy the “Service Name” not the “Display Name” Many times they are the same but not always. Right click on the service in services.msc to see the two on the general tab and make sure you are doing “Net Start servicename” – and as said above, you still have to put it in quotes if it’s got spaces.

    You can change the name with sc to make it easier if you want but obviously, this might be a bad idea with system/windows services.

  14. ctcadmin says:

    Thank you for pointing out the important difference between “Service Name” and “Display Name”.

    Yes, we do mention the need to use the “Service Name” in the article, but maybe there is a way to make it more prominent. We’ll think about it — let us know if you have any ideas that don’t detract from the main focus of the article (using NET).

    Note that our free ServicePilot utility (a more fully-featured alternative to NET.EXE) removes the name confusion by accepting both the “Service Name” and the “Display Name”. You can use either one!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>