Stop programs from running

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
joe
Posts: 35
Joined: 06 Sep 2017 07:56

Stop programs from running

#1 Post by joe » 09 Sep 2017 23:54

hi
hope you guys r enjoying weekend.

can anyone help me with a batch script to check only one application at a time

ie

notepad.exe
calc.exe
wordpad.exe
mspaint.exe

if notepad.exe is running then the other three should not run.
the same condition for the other 3.

thanks
Last edited by Squashman on 10 Sep 2017 12:24, edited 1 time in total.
Reason: MOD EDIT: Added Descriptive thread title.

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: please help

#2 Post by Compo » 10 Sep 2017 03:25

Could you please try to better describe what it is you want to do instead of what you don't want to do.

Your question as I see it:
If any one of notepad.exe, calc.exe, wordpad.exe or mspaint.exe are running start none of them else start one of them.

Question raised:
If none of them are running which one of the four do you want run?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: please help

#3 Post by aGerman » 10 Sep 2017 05:15

You could filter the tasks using FINDSTR and count using FIND.

Code: Select all

@echo off &setlocal
for /f %%i in (
  'tasklist /nh^|findstr /lbi "notepad.exe calc.exe wordpad.exe mspaint.exe"^|find /c /v ""'
) do set "cnt=%%i"
echo %cnt% of 4 running.
pause

Note that the process name of the calculator changed on Win10. It's now calculator.exe.

Steffen

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: please help

#4 Post by Squashman » 10 Sep 2017 12:23

Sounds like you are trying to block applications from running if some other app is running. I wouldn't recommend trying to do this with a batch file.

Post Reply