|
Answer» Hi all, Trying to WORK out a way to identify (& report) if OUTLOOK is running and if TRUE, kill the application. I know how to kill the application and get it started again, HOWEVER my issue is trying to work ouot the logic required to properly identify the report of such. I've provided below a snippet of the code from my current script that deals with what I've mentioned.
Code: [Select]tasklist /FI "IMAGENAME eq OUTLOOK.EXE" > NUL if ERRORLEVEL 1 tasklist /FI "IMAGENAME eq OUTLOOK.EXE" && tasklist /FI "IMAGENAME eq OUTLOOK.EXE" >> %OutputLog% if ERRORLEVEL 0 @echo ** OUTLOOK NOT RUNNING TO TERMINATE. && @echo ** OUTLOOK NOT RUNNING TO TERMINATE. >> %OutputLog% && goto :EOF :Finx @echo. >> %OutputLog% && @echo.
sleep 3
taskkill /FI "IMAGENAME eq OUTLOOK.EXE" >> %OutputLog% 2>&1 && @echo OUTLOOK TERMINATED SUCCESSFULLY. && @echo OUTLOOK TERMINATED SUCCESSFULLY. >> %OutputLog% @echo. >> %OutputLog% && @echo.
sleep 5
tasklist /FI "IMAGENAME eq OUTLOOK.EXE" > NUL if ERRORLEVEL 1 @echo ** OUTLOOK STILL RUNNING. && @echo ** OUTLOOK STILL RUNNING. >> %OutputLog% && goto :EOF if ERRORLEVEL 0 tasklist /FI "IMAGENAME eq OUTLOOK.EXE" && tasklist /FI "IMAGENAME eq OUTLOOK.EXE" >> %OutputLog% :Fin3 @echo. >> %OutputLog% && @echo.Any HELP appreciated.Not sure that tasklist SETS an errorlevel. My results show either getting an errorlevel zero (if the program is running) or the message "INFO: No tasks running with the specified criteria"
Can you produce an errorlevel 1 with tasklist?
8-) I thougt I had during commad-line testing. Quick look about & I couldn't find any reference to EXIT/ERROR codes for tasklist (shame that). Have reolve by piping it through the find comand ..... (for the benefit of anyone who's interested).
Code: [Select]@echo ************************************************ >> %OutputLog% @echo ** ** >> %OutputLog% @echo ** TERMINATING OUTLOOK.EXE IN 5 SECONDS ** >> %OutputLog% @echo ** ** >> %OutputLog% @echo ************************************************ >> %OutputLog% @echo ************************************************ @echo ** ** @echo ** TERMINATING OUTLOOK.EXE IN 5 SECONDS ** @echo ** ** @echo ************************************************
sleep 3
@echo. >> %OutputLog% && @echo. tasklist /FI "IMAGENAME eq OUTLOOK.EXE" 2>&1 | find "OUTLOOK.EXE" > NUL 2>&1 if ERRORLEVEL 1 @echo ** OUTLOOK NOT RUNNING TO TERMINATE. && @echo ** OUTLOOK NOT RUNNING TO TERMINATE. >> %OutputLog% && goto :EOF if ERRORLEVEL 0 tasklist /FI "IMAGENAME eq OUTLOOK.EXE" && tasklist /FI "IMAGENAME eq OUTLOOK.EXE" >> %OutputLog% && @echo. >> %OutputLog% && @echo. :Finx
:RedoKill sleep 3
taskkill /FI "IMAGENAME eq OUTLOOK.EXE" >> %OutputLog% 2>&1 @echo. >> %OutputLog% && @echo.
sleep 3
tasklist /FI "IMAGENAME eq OUTLOOK.EXE" 2>&1 | find "OUTLOOK.EXE" > NUL 2>&1 if ERRORLEVEL 1 @echo OUTLOOK TERMINATED SUCCESSFULLY. && @echo OUTLOOK TERMINATED SUCCESSFULLY. >> %OutputLog% && goto :Fin3 if ERRORLEVEL 0 @echo ** OUTLOOK STILL RUNNING - RETRYING KILL STEP. && @echo ** OUTLOOK STILL RUNNING - RETRYING KILL STEP. >> %OutputLog% && @echo. >> %OutputLog% && @echo. && goto :RedoKill :Fin3 @echo. >> %OutputLog% && @echo.
sleep 3
goto :EOF[/font][/size][/color]
Thanks for taking a look Sidewinder.All done.
Figured others might want to use .... if so, enjoy.
Late NOTE: You'll need to have a copy of ROBOCOPY.
Edit: Which can be found in the following Resource Kit [ http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en ]
|