Batch file help - check for running task, if not running then start .exe(s)

Hi there,

I'm trying to create a batch script that checks to see if there's a windows task\process running, however I don't believe I've got the script completely right, essentially what I'm looking to do is to check if WVDSTrayApp.exe is running then do nothing, if it is not running then start these .exe(s):

start X:\"PC Software"\DataService\WVDSTrayApp.exe
start X:\"PC Software"\INDILink\INDILinkPCComms.exe
Start X:\"PC Software\Ui\WVS Ui.exe"

Here's my script so far:

@echo off

tasklist /FI IMAGENAME eq "WVDSTrayApp.exe" 2>NUL | find /I /N "WVDSTrayApp.exe">NUL
if "%ERRORLEVEL%"=="0" echo GOTO END

If exist x:*.* subst X: /d
Subst X: d:\paradigm
x:

start X:\"PC Software"\DataService\WVDSTrayApp.exe
start X:\"PC Software"\INDILink\INDILinkPCComms.exe
Start X:\"PC Software\Ui\WVS Ui.exe"

:END
exit

Tasklist (confirm WVDStrayapp.exe):

U:\>tasklist

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
System Idle Process              0 Services                   0          4 K
System                           4 Services                   0      9,244 K
smss.exe                       308 Services                   0      1,104 K
csrss.exe                      428 Services                   0      3,848 K
wininit.exe                    480 Services                   0      3,592 K
services.exe                   584 Services                   0      9,472 K
lsass.exe                      592 Services                   0     17,448 K
svchost.exe                    660 Services                   0     13,936 K
svchost.exe                    704 Services                   0      9,652 K
MsMpEng.exe                    792 Services                   0    135,264 K
svchost.exe                    888 Services                   0     40,768 K
svchost.exe                    956 Services                   0     85,080 K
svchost.exe                   1000 Services                   0     24,748 K
svchost.exe                    640 Services                   0     79,392 K
svchost.exe                   1088 Services                   0     29,292 K
spoolsv.exe                   1260 Services                   0     16,444 K
svchost.exe                   1292 Services                   0     27,712 K
armsvc.exe                    1452 Services                   0      4,152 K
svchost.exe                   1480 Services                   0      7,372 K
svchost.exe                   1544 Services                   0      8,768 K
agentmonitor.exe              1632 Services                   0      4,292 K
aeagent.exe                   1640 Services                   0     19,400 K
svchost.exe                   1672 Services                   0      3,276 K
svchost.exe                   1724 Services                   0      3,252 K
conhost.exe                   1768 Services                   0      2,568 K
sqlwriter.exe                 1880 Services                   0      5,612 K
winvnc.exe                    1940 Services                   0      4,356 K
svchost.exe                   1956 Services                   0      8,108 K
svchost.exe                   2352 Services                   0      4,692 K
WmiPrvSE.exe                  2852 Services                   0     28,192 K
NisSrv.exe                    2948 Services                   0        636 K
svchost.exe                   1700 Services                   0      9,328 K
SearchIndexer.exe             2896 Services                   0     37,632 K
CcmExec.exe                   2072 Services                   0     58,948 K
CmRcService.exe               4252 Services                   0      9,772 K
WmiPrvSE.exe                  4260 Services                   0      9,052 K
WmiPrvSE.exe                  4368 Services                   0     12,648 K
WmiPrvSE.exe                  4592 Services                   0     10,004 K
WmiPrvSE.exe                  4724 Services                   0      5,740 K
WmiPrvSE.exe                  4932 Services                   0     12,244 K
taskhost.exe                  3472 Services                   0     11,952 K
agent.exe                     3876 Services                   0    116,912 K
AgentMaint.exe                5560 Services                   0     13,684 K
NableSixtyFourBitManager.     7684 Services                   0     13,068 K
NableReactiveManagement.e     5036 Services                   0     43,532 K
conhost.exe                   1472 Services                   0      2,552 K
conhost.exe                   4900 Services                   0      2,544 K
WmiPrvSE.exe                  4112 Services                   0     13,100 K
ntrcloud_https_en.exe         8616 Services                   0     23,916 K
svchost.exe                   3336 Services                   0     15,796 K
csrss.exe                     5532 Console                    3     18,352 K
winlogon.exe                  2268 Console                    3      4,940 K
rundll32.exe                  5976 Console                    3     25,208 K
dwm.exe                       3240 Console                    3     24,548 K
winvnc.exe                    8960 Console                    3      6,700 K
taskhostex.exe                7352 Console                    3      8,072 K
explorer.exe                  6088 Console                    3     83,316 K
dllhost.exe                   2956 Console                    3      7,136 K
msseces.exe                   3132 Console                    3     13,080 K
SCNotification.exe            3036 Console                    3     22,980 K
igfxsrvc.exe                  8768 Console                    3      6,180 K
hkcmd.exe                     4124 Console                    3      5,748 K
igfxpers.exe                  2184 Console                    3      5,952 K
WVDSTrayApp.exe               8876 Console                    3     26,996 K
INDILinkPCComms.exe           6680 Console                    3     33,656 K
sqlservr.exe                  5928 Console                    3    110,380 K
RAVBg64.exe                   2992 Console                    3      2,612 K
RAVCpl64.exe                  8628 Console                    3      2,692 K
audiodg.exe                   3868 Services                   0     10,736 K
WVDSTrayApp.exe               4924 Console                    3      3,088 K
cmd.exe                       3248 Console                    3      2,624 K
conhost.exe                   7980 Console                    3      4,700 K
tasklist.exe                  8668 Console                    3      5,416 K
ProjNetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Your tasklist.exe syntax is incorrect, which you didn't see because you redirected stderr.
There's no need to redirect the error output, if the task isn't found, only an information will be written to stdout.
Try it like this:
@echo off

 tasklist.exe /FI "IMAGENAME eq WVDSTrayApp.exe" | find /I /N "WVDSTrayApp.exe">NUL
 if "%ERRORLEVEL%"=="0" echo GOTO END

 If exist x:*.* subst X: /d
 Subst X: d:\paradigm
 x:

 start "" "X:\PC Software\DataService\WVDSTrayApp.exe"
 start "" "X:\PC Software\INDILink\INDILinkPCComms.exe"
 Start "" "X:\PC Software\Ui\WVS Ui.exe"

 :END
 exit

Open in new window

0
ProjNetAuthor Commented:
hi thanks for your posting, I updated the script, however it hasn't worked, here's the screenshot as you can see the .exe is running but the script still called the .exe(s)

Script Error
0
oBdACommented:
Sorry, too much copy and paste.
In addition to the tasklist syntax error, you had an echo in front of the goto in line 4.
@echo off

 tasklist.exe /FI "IMAGENAME eq WVDSTrayApp.exe" | find /I /N "WVDSTrayApp.exe">NUL
 if "%ERRORLEVEL%"=="0" GOTO END

 If exist x:*.* subst X: /d
 Subst X: d:\paradigm
 x:

 start "" "X:\PC Software\DataService\WVDSTrayApp.exe"
 start "" "X:\PC Software\INDILink\INDILinkPCComms.exe"
 Start "" "X:\PC Software\Ui\WVS Ui.exe"

 :END
 exit

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ProjNetAuthor Commented:
Great, this seems to have worked.

Thanks for your assistance :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.