Script to identify 2 active services, take down the 2 and go up only 1

Asked

Viewed 275 times

2

Next, I have a service here in my environment that runs on some machines, however this service can not be duplicated ( can not have 2 active services at the same time ) I wonder if it is possible to write a script that checks whether it has 2 active services or more, disable the 2 or more and activate only 1?

1 answer

1


in Rtlservice, change to the desired service name. The script will loop, and whenever there is more than 1 of this service it will finish all of this type, and will start again the service.

@echo off
mode 100,2
:loop
cls

set servico=RtlService

if not exist %tmp%\servdupl (md %tmp%\servdupl)

cd %tmp%\servdupl

tasklist | find /i "services" | find /i "%servico%">servdupl.txt

type "servdupl.txt" | find /v /c "">num.txt

set /p num=<num.txt

if "%num%" gtr "1" (net stop %servico%

net start %servico%
goto loop)
  • Tip: in case you want to know the correct service name, type NET START in the prompt and you will see the list with the services that were started in Windows! (Tested on Windows 7)

  • Thanks for the reply Cristian, this scribe is to be saved as VBS ? OBS : I am using windows10

  • as . cmd or . bat

Browser other questions tagged

You are not signed in. Login or sign up in order to post.