Hi guys,
Is there someone who can point me in the right direction.
My end goal is to have a batch file that will kill a application but keep checking to see when the application has successfully closed down. Then open another application.
So if i do a taskkill /im app.exe
This will then get the application to pop up and ask if you would like to close so until the user presses yes to this question the application is still open.
I could force it but i would prefer for the application to shut down properly.
Has anyone any ideas how i can for a "taskkill /im app.exe" then get it to check to see when its closed wait 5 seconds then run the new application.
Thanks in advance
Jonny
Taskkill and then start another prosess
Moderator: DosItHelp
Re: Taskkill and then start another prosess
Use TASKLIST to see if it is still running and keep looping back until it is not running anymore.
Re: Taskkill and then start another prosess
Squashman wrote:Use TASKLIST to see if it is still running and keep looping back until it is not running anymore.
Thanks i will have a look at this
Re: Taskkill and then start another prosess
Here is a piece of code I use a lot.
Code: Select all
SET TM1CE=TM1ChoreExecute
:TM1LOOP
tasklist | find /C "%TM1CE%" >nul
IF %ERRORLEVEL%==1 SET TM1C=False & GOTO TM1CNR
ECHO ********************************************************>>%logfile%
ECHO %TM1CE% is currently running >>%logfile%
ECHO Will loop until %TM1CE% is avaiable for processing >>%logfile%
ECHO ********************************************************>>%logfile%
PING -n 10 127.0.0.1>nul
GOTO TM1LOOP
:TM1CNR
:: start your program here ::
Re: Taskkill and then start another prosess
Hi guys well i have go this far so far.
It keeps returning the errorlevel as 1 even when the program is not running. So i thinki have done something worng.
I have changed the way it works a little as thinking about it if i was to loop it and the program was never to close it would just keep looping.
It keeps returning the errorlevel as 1 even when the program is not running. So i thinki have done something worng.
I have changed the way it works a little as thinking about it if i was to loop it and the program was never to close it would just keep looping.
Code: Select all
@echo on
taskkill /im myapp.exe
echo App is Closing Down Please wait...
ping -n 5 127.0.0.1>nul
tasklist /FI "IMAGENAME eq myapp.exe" >nul | find /I /N "myapp.exe"
IF "%ERRORLEVEL%"=="1" PING -n 5 127.0.0.1>nul
echo Waiting for program to close
tasklist /FI "IMAGENAME eq myapp.exe" >nul | find /I /N "myapp.exe"
IF "%ERRORLEVEL%"=="0" START C:\location\myapp.exe &exit
tasklist /FI "IMAGENAME eq myapp.exe" >nul | find /I /N "myapp.exe"
IF "%ERRORLEVEL%"=="1" PING -n 5 127.0.0.1>nul
echo Waiting for program to close
tasklist /FI "IMAGENAME eq myapp.exe" >nul | find /I /N "myapp.exe"
IF "%ERRORLEVEL%"=="0" START C:\location\myapp.exe &exit
tasklist /FI "IMAGENAME eq myapp.exe" >nul | find /I /N "myapp.exe"
IF "%ERRORLEVEL%"=="1" PING -n 5 127.0.0.1>nul
echo Waiting for program to close
tasklist /FI "IMAGENAME eq myapp.exe" >nul | find /I /N "myapp.exe"
IF "%ERRORLEVEL%"=="0" START C:\location\myapp.exe &exit
echo Program was not closed. Please try again
Re: Taskkill and then start another prosess
hemmjonny wrote:Hi guys well i have go this far so far.
It keeps returning the errorlevel as 1 even when the program is not running. So i thinki have done something wrong.
Correct. Errorlevel 1 means the FIND command did not find anything from the output of the tasklist command which means the program is not running.
If the FIND command did find the output from the tasklist command it would be errorlevel 0, which means the program is still running.
Re: Taskkill and then start another prosess
Ah ok that means i have it the wrong way round
I have this but still not right even if the app is open it will open a new one. no matter what is seems to report back errorlevel 1.
Any ideas what i am doing wrong?
Thanks
Jonny
Code: Select all
@echo on
taskkill /im myapp.exe
echo App is Closing Down Please wait...
ping -n 5 127.0.0.1>nul
cd c:\location\
tasklist /FI "IMAGENAME eq myapp.exe" >nul | find /I /N "myapp.exe"
IF "%ERRORLEVEL%"=="0" PING -n 5 127.0.0.1>nul
echo Waiting for program to close
tasklist /FI "IMAGENAME eq myapp.exe" >nul | find /I /N "myapp.exe"
IF "%ERRORLEVEL%"=="1" START myapp.exe
PAUSE
I have this but still not right even if the app is open it will open a new one. no matter what is seems to report back errorlevel 1.
Any ideas what i am doing wrong?
Thanks
Jonny
- Attachments
-
- batch.PNG (31.67 KiB) Viewed 5640 times
Re: Taskkill and then start another prosess
Why on earth are you hiding the name of the executable?
…providing that may help to narrow down your problem, (especially as it looks like you are specifically running the script As administrator)
…providing that may help to narrow down your problem, (especially as it looks like you are specifically running the script As administrator)