Create Batch File to Start or End Window Services

Contributor Icon Contributed by davak Date Icon November 28, 2003  
Tag Icon Tagged: Batch file programming  

The windows environment can be easily changed by starting or ending various windows services. For example, this method can be used to easily shut down multiple services for a performance boost during game playing.


Warning: Manipulating windows services can have unpredictable effects on your system. You should create a system restore point before experimenting.

We all want to tweak or windows systems to the extreme to get the quickest, most powerful system possible. Many people will disable multiple window services manually before game playing. What a pain!

Many times people forget what the services do or forget to restart the important ones. Services can be easily changed by creating batch files.

The important commands are the following:
NET START – starts the service
NET STOP – ends the service

For example:
NET STOP "Error Reporting Service"

Output: The Error Reporting Service service was stopped successfully.

Knowing the commands, one can now easily create batch files called something like beforegame.bat and aftergame.bat.

Before.bat would contain all the NET STOP commands to end the nonessential services.
After.bat would be exactly the same except all the NET STOP commands would be replaced with NET START commands to restart all the common services.

A sample of the before.bat file might look something like this:

NET STOP "Error Reporting Service"
NET STOP "FTP Publishing Service"
SET STOP "IIS Admin"
NET STOP "Messenger"

Likewise, the after.bat file might look something like this:

NET START "Error Reporting Service"
NET START "FTP Publishing Service"
SET START "IIS Admin"
NET START "Messenger"

You may wish to reference this: list of services that can be disabled.

If your system ever becomes unstable and you want to return the services to their default settings, the default settings for the windows services can be found here.

 
  • Mazz
    Wickidellic!
  • Fuzoukwu
    To list all running services in Win XP issue the following command at the prompt:
    C\>tasklist
    Have not tried it on Vista but it is likely to work also
  • ilaya
    check the particular service running or not in all 100 servers.we need to check this using single server using bat file
  • Swati Gudla
    Hello Everyone,
    I am very new to windows services.
    My question is..
    Is there any DOS command to figure out the running services.
    To be specific i have a windows service like "my service" i need to check the service is running or not..Is there any command to execute and see the running services...
    I would really appreciate if some one can help me out to ....
  • ilaya
    can u help me bellow issue

    check the particular service running or not in all 100 servers.we need to check this using single server.
  • vladanl
    sc query "my service"

    and

    net start
  • ilaya
    hi sir,

    please find the below sceneraio and help me to fix this, request you to provide bat and script file for this.


    unix,windows

    We have more than 100 servers in our environment, each server we have seperate user account. Need to change the password for all 100 servers from one server.



    windows

    check the particular service running or not in all 100 servers.we need to check this using single server.
  • delea
    I created batch file having this entry NET STOP "MSSQLSERVER" and it is prompting me to accept Y before execution.
    How can I correct this to make auto-execute?
  • aarfie
    Ya Finger Crossed,
    i Was looking for Same.
    Thanks,
    Ahmad
  • malaa
    Nice one, I think it could help me cos am having a work station with oracle, SAP and microsoft SQL Server
  • Ravi
    Thanks, But how to Enable / Disable Windows Services using DOS.

    If the service is disabled, we cannot start the service using '' net start command ''

  • ramr
    Would be nice to clearly add where those files should be located.

    Thks, Regards
  • leighw
    Does anyone know how to DISABLE a service (not just stop it) so that it wont start again on the next reboot? I have tried the following: -

    NET STOP "Service Name" (The service stops after a second or two)
    SC Config "Service Name" start= disabled

    But this error is produced on the second line: -

    [SC] OpenService FAILED 1060: The specified service does not exist as an installed service.

    Patently the service does exist as it was stopped successfully in the first line.

    Thanks, Leigh
  • mrxbubbles
    try double quotes on the second one around the service name
  • Anonymous
    Sometimes you might run into a problem using the NET command. You may find yourself getting this error:

    'net' is not recognize as an internal or external command.

    When that happens, this usually indicates that there is a problem with your PATH setting. To fix this, while in a command prompt, type PATH and hit the [enter] key. Your PATH variable may be long or short, depending on what programs have modified it, what you've done, etc..

    What you need to do is make sure that you have C:WindowsSystem32 as the first location in the PATH line (assuming you are using WinXP). To fix the problem, type:

    PATH %SystemRoot%System32

    And add any other path locations that may already be listed before you modified the path. Separate each individual path location with a semi-colon ( ; ).

    I usually keep my path variable simple:

    PATH %SystemRoot%System32;%SystemRoot%;%SystemRoot%Progra~1;C:;D:;E:

    EDIT: Sometimes setting this through a command prompt will not work, as the PATH variable may automatically be reset to what it was before you modified it. If this is the case, you can change the path by the following alternative method (assuming you're using WinXP):

    Right-click on "My Computer" and choose "Properties"
    Click the "Advanced" tab
    Click the "Environment Variables" button
    In the "System Variables" box, click on "Path", and click "Edit"
    Make the changes to your path variable, then click "Ok"
    Click "Ok" to exit all dialog windows.

    This should save your PATH variable correctly.
  • savita
    Hi,

    I am using net start to start a service. but my service name has sqaure brackets soemthign like abc[32.0] and becuase of square braces its failing. does anyone know escapae sequence for this?

    many thanks
    savita.
  • ilaya
    can u help me bellow issue

    check the particular service running or not in all 100 servers.we need to check this using single server.
  • sl
    how about:

    sc \servername STOP "Servicename"

    where sc is the service control utility in resource kit. You can use START to start a service and other switches to do the following:

    sc \servername config servicename start=(boot, system, auto, demand, disabled)
  • billvts
    Is there a way that I can make a batch file start a service if it is stopped but stop it if it is started, if that makes sense?

    Any help would be greatly appreciated!
  • bd
    Exactly what I was looking for.
blog comments powered by Disqus