Programming Field

Schtasks /End - DOS/Command Prompt Reference

Stops the registered scheduled task if it is currently running. This is one of the commands (options) of Schtasks.

Syntax

schtasks[.exe] /End [/S <remote-system> [/U <user-name> [/P [<password>]]]]
    /TN <task-name> [/HRESULT]

Options

/S <remote-system> Specifies the name of the computer (local/remote) where the task is registered. <remote-system> will be an IP address or hostname. If omitted, the local computer is the target.
/U <user-name> [/P [<password>]]

Specifies the login name and password when providing a computer name. You can specify a domain name in <user-name> (in the form of ‘domain\username’). If omitted, the user who executed this command will be used.

On ‘/P [<password>]’, if the entire ‘/P [<password>]’ is omitted, no password is set. If only ‘/P’ is specified (and ‘<password>’ is omitted), prompting the user to enter the password will occur (the entered password will be displayed as ‘*’ in the prompt).

/TN <task-name> Specifies the name of the task. If the task name contains space characters, you need to enclose it with ‘" "’. If the task exists within a folder hierarchy, include the path to the task as well.
/HRESULT [Windows 10? or later] Changes the exit code of the Schtasks command to HRESULT. This is used when you want to perform detailed handling in case of errors.

Details

Stopping a task with ‘/End’ results in the termination of the program similar to a forced termination. Also, if the task's program is running child processes, those processes will also be forcefully terminated (though, in cases where the child program is a GUI program, it may not terminate).

If you use ‘/End’ to stop the execution, a record stating ‘The last run of the task was terminated by the user. (0x41306)’ will be logged. You can review this record in the Task Scheduler.

Samples

Sample

schtasks /end /tn HogePiyo

Forcefully terminate the execution of the program if the task ‘HogePiyo’ is currently running.

See also