Stopping services, restarting services(safemode)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
crobertson
Posts: 20
Joined: 25 May 2012 12:34

Re: Stopping services, restarting services(safemode)

#16 Post by crobertson » 10 Aug 2012 11:17

Liviu,
That seem to work well.
I put some pauses in it so I can see it as it works. Is there a way to >> push the disabled ones into a text file, then start disabled.txt
I want to stop those currently running, and disable them from restarting. Of course I will need to list AV services as to not disable them, but if they are any good, they don't allow that (which is a test I want)

So currently this code only stops those stoppable but does it disable all those not in the list?
This is why I was shooting for just stopping and disabling anything not in the list. I wouldn't use this on computers with specialized services of course.
By the way, thank you for your help. Please understand, these are the services I would be turning off anyway, just more automated.

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Stopping services, restarting services(safemode)

#17 Post by Liviu » 10 Aug 2012 13:30

crobertson wrote:Is there a way to >> push the disabled ones into a text file
Assuming you mean "stopped" rather than "disabled", yes, all you need to do is add a line "if exist disabled.txt del disabled.txt" before the top for loop, then right after "net stop" insert a line "echo %svcex%>>disabled.txt".
crobertson wrote:then start disabled.txt

Code: Select all

for /f "delims=" %%x in (disabled.txt) do @echo net start "%%x"

crobertson wrote:So currently this code only stops those stoppable but does it disable all those not in the list?
Only stops, the disabling part popped up later in the thread. If you really have to do that, lookup "sc config start=".

crobertson wrote:Please understand, these are the services I would be turning off anyway, just more automated.
Just as a note, even the "turning off" part is not guaranteed to always work, and can't be made to work reliably using a simplistic batch+whitelist solution. For example, it is technically possible that the next millisecond after you "net stop" a service, another service which comes later in the alphabetical list (and has not been stopped yet) needs the first service and restarts it manually.

Liviu

crobertson
Posts: 20
Joined: 25 May 2012 12:34

Re: Stopping services, restarting services(safemode)

#18 Post by crobertson » 19 Dec 2015 12:55

To complete this topic, I created a batch that disables all but a few necessary services. It is similar to safe mode. It has been a great success and allows us to install programs to scan. An alternative we have found was a little utility that enabled services in safe mode to allow installations.
We also use a similar batch to disable multiple services that really increase the computers speed. Thanks all for the help.

Post Reply