Stop service using batch file

Pherule

Distinguished
Aug 26, 2010
591
0
19,010
I've searched Google, I've read other threads on this, but got no clear answer.

I'm in need of a batch file that will set a service's startup type to disabled AND immediately stop the service if it is currently running as well. I've never dealt with batch files before. How do I go about doing this?

I would also need some way of making the batch file run on every startup. I assume an easy way to do this would be to put a shortcut to the batch file to the startup menu in the start menu (I'm using classic start menu)
 

Wolfshadw

Titan
Moderator
EDIT - Just noticed this is for Windows 8. Not sure if this is at all relevant as I'm not familiar with Windows 8

Batch files are simply lines of commands saved into a file with a ".bat" extension. Example - mystartup.bat.
You can create and save these files using any text editor like notepad.
Saving the file in your startup folder will have the batch file execute each time you boot your system.
The command line for starting and/or stopping a service is as follows:

Code:
net start <servicename>
net stop <servicename>

The command for setting a service start to disabled is as follows:

Code:
sc config <servicename> start= disabled

So if you wanted to shut down and disable a service called "indexing", you would create a batch file with the following two lines of code"

Code:
net stop indexing
sc config indexing start= disabled

Note the spacing as apparently, it's required.

-Wolf sends