I have several scheduled tasks that each execute a (different) batch file. Each batch file calls into the same program, with with separate command line arguments. If I Stop a task while it's running, the program in the batch file still runs. (The batch file is a one-liner that simply executes the program.)

How can I force the program launched from a batch file to force quit when I Stop the task that calls the batch file?

As a work around, I'm look for the task in the running processes, and kill it by process id. I'd like a cleaner solution that's managed from the Task Scheduler.

  • Did you know the name of the process launched by your batch ? or edit your question and post your batch code. To list all scheduled tasks type this command line Schtasks /query /fo LIST – Hackoo Mar 19 '16 at 3:11

This an example to kill some process like "Taskhost.exe" "SSScheduler.exe" "taskeng.exe" so you can add or remove some process to be killed in this batch; just you should know the name of the process to be killed.

@echo off
cls & color 0A
Mode con cols=60 lines=6
Title ProcessKiller by Hackoo 2016
:: Automatically check & get admin rights
REM  --> Check for permissions
Reg query "HKU\S-1-5-19\Environment">nul 2>&1
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
ECHO            **************************************
ECHO             Running Admin shell... Please wait...
ECHO            **************************************

    goto UACPrompt
) else ( goto gotAdmin )

    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    del "%temp%\getadmin.vbs"
    exit /B

set process="Taskhost.exe" "SSScheduler.exe" "taskeng.exe"
set Tmp=Tmp.txt
set LogFile=ProcessKillerLog.txt
If Exist %Tmp% Del %Tmp%
If Exist %LogFile% Del %LogFile%
For %%a in (%process%) Do Call :KillMyProcess %%a %Tmp%
Cmd /U /C Type %Tmp% > %LogFile%
If Exist %Tmp% Del %Tmp%
Start "" %LogFile%
Exit /b

ECHO             **************************************
Echo               Trying to kill "%~1"
ECHO             **************************************                       
Echo The Process :  "%~1"  
Taskkill /IM "%~1" /F /T
Echo =======================
)>>%2 2>&1
| improve this answer | |
  • 4
    I understand how to kill a process. I'm more interested in how to kill a process when the task is Stopped in Task Scheduler. – Christopher Stevenson Mar 21 '16 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.