Script to identify 2 active services, drop the 2 and upload only 1

1

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

    
asked by anonymous 16.04.2018 / 21:13

1 answer

0
  

In RtlService , change to the name of the service you want.   The script will loop, and whenever there is more than 1 of this service    it will terminate all of that type, and will start the service again.

@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)
    
18.04.2018 / 02:44