|
Answer» I need help with the following batch program, it is supposed to check for the EXE WebFormApp.exe, if it is running then it should start Internet explorer. Otherwise it should start the WebFormApp.exe and then start Internet Explorer. the batch file below only works if the WebFormApp.exe is running. meaning it will open Internet Explorer. When the program is not running, it will run it and the cmd window will stay open.
what is the best way for me to do this?? I need this batch to be able to run WebFormApp.exe when ProcessNotFound is true, then launch Internet explorer. I'm a novice at this and your detailed help is greatly appreciated.
:ProcessNotFound echo %EXE% is not running "C:\Program Files (x86)\Common Files\STF SERVICES Shared\WebFormApp.exe" -start
echo off SETLOCAL EnableExtensions set EXE=WebFormApp.exe
FOR /F %%X IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto ProcessFound
goto ProcessNotFound
:ProcessFound echo %EXE% is running start "C:\Program Files\Internet Explorer" IEXPLORE.EXE taxandaccounting.bna.com/btac/ goto END
:ProcessNotFound echo %EXE% is not running "C:\Program Files (x86)\Common Files\STF Services Shared\WebFormApp.exe" -start goto END
:END echo Finished!
thanksWithout having WebFormApp.exe in front of me, I don't know what the -start switch does, so I'll take if for granted that it's what you want. One of the things you should know is that you never start the WebFormApp.exe after you start iexplorer. Here is something to try:
Code: [Select]echo off SETLOCAL EnableExtensions set EXE=WebFormApp.exe
REM you can also use tasklist's /im "imagename" switch FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto ProcessFound
goto :ProcessNotFound
:ProcessFound echo %EXE% is running start "C:\Program Files\Internet Explorer" IEXPLORE.EXE taxandaccounting.bna.com/btac/ REM I removed this ' goto :END ' statement so that it will continue down to start WebFormApp.exe.
:ProcessNotFound echo %EXE% is not running "C:\Program Files (x86)\Common Files\STF Services Shared\WebFormApp.exe" -start goto :END
:END echo Finished!This is what I came Up with You will have to fix where the files are and the exe and stuff.
Code: [Select]echo off title BLA ::WILL NOT WORK UNLESS YOU FIX WHERE THE FILES AND FOLDERS ARE!!! :presets set exe=blah set isRunning=unknown if "%isRunning%" == "unkown" ( ::Copyed Code of Yours FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% ( set isRunning=yes ) else ( set isRunning=no ) ) goto start :start if "%isRunning%" == "yes" ( start folders/ie.exe goto end ) if "%isRunning%" == "no" ( start folders/%blah%.exe set isRunning=yes if "%isRunning%" == "yes" ( start folders/ie.exe goto end ) )
:end echo I'm done ping localhost -n 3 >nul exitThank you for all your replies, I spoke to the vendor of the application and he tells me that the -start switch has to be at the end of the path otherwise the program will not start from a batch file. example "C:\Program Files (x86)\Common Files\STF Services Shared\WebFormApp.exe" -start . the problem is when the batch RUNS the cmd window never closes... I tried Exit and taskkill, but the batch file never reads anything past -start.
I will attach the msi file for WebFormApp.exe if anyone is WILLING to help. the file size is 1.7MB therefore I can't upload it here... but willing to send by email or it can be downloaded from Bloomberg Tax and accounting center.
thank.Batch files do sequential processing. What this means is that if you launch an application from your batch file it will wait for that application to finish and exit before it MOVES on to the next command. The work around for this as Shiverbob has pointed out is to use the internal START command to execute your application. This spawns a new process and returns control back the batch file.
So you need to do something like this.
Code: [Select]START "Launching WebFormApp" "C:\Program Files (x86)\Common Files\STF Services Shared\WebFormApp.exe" -startSquashman - thank you for your help, your suggestion worked.
|