If statement for two running processes

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
RedCellNL
Posts: 2
Joined: 28 Feb 2013 02:18

If statement for two running processes

#1 Post by RedCellNL » 28 Feb 2013 02:23

Hi all,

I am writing a script to check if two (or more) instances of the same process is running and then run a command.
I have the following code:


:QueryProcess
tasklist | findstr wfica32.exe > nul 2>&1
IF wfica32.exe EQU 1 goto QueryProcess
IF wfica32.exe EQU 2 goto END
goto END

:End
taskkill /F /IM iexplore.exe > nul 2>&1
Exit



But this does not work. Can anyone help me with the code so iexplore gets closed when running more then one instance?

Thanks!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: If statement for two running processes

#2 Post by foxidrive » 28 Feb 2013 03:10

Try this:

Code: Select all

@echo off
:loop
for /f %%a in ('tasklist ^|find /i /c "wfica32.exe" ') do (
if %%a GEQ 2 taskkill /F /IM "iexplore.exe" >nul
)
ping -n 60 localhost >nul
goto :loop

RedCellNL
Posts: 2
Joined: 28 Feb 2013 02:18

Re: If statement for two running processes

#3 Post by RedCellNL » 28 Feb 2013 14:42

Thanks!
Got it working!

Post Reply