Detect scheduled task creation with schtasks (KQL)
Scheduled tasks are a durable persistence mechanism: a task can re-launch a payload at logon, on a timer or at system start. This DeviceProcessEvents query matches schtasks.exe command lines that create (/create) or change (/change) a task, surfacing the full command so you can see what the task runs and when.
It pairs well with the registry Run-key query — together they cover the two most common autostart persistence paths on Windows.
The query
DeviceProcessEvents
| where Timestamp > ago(7d)
| where FileName =~ "schtasks.exe"
| where ProcessCommandLine has_any ("/create", "/change")
| project Timestamp, DeviceName, AccountName,
InitiatingProcessFileName, InitiatingProcessCommandLine, ProcessCommandLine
| sort by Timestamp descLine-by-line explanation
| where FileName =~ "schtasks.exe"Scopes to the command-line task scheduler binary.
| where ProcessCommandLine has_any ("/create", "/change")Keeps task creation and modification, the actions that establish or alter persistence, and drops /query and /run noise.
project ... InitiatingProcessFileName, ProcessCommandLineShows the parent process and the full schtasks command, including the action, trigger and the program the task will run.
Required tables and columns
FileNameThe image; schtasks.exe.ProcessCommandLineFull command line with the task action, trigger and target program.InitiatingProcessFileNameThe parent that created the task, useful for spotting script-driven persistence.AccountNameAccount that created the task; SYSTEM or admin context raises impact.
MITRE ATT&CK mapping
Tuning and false positives
- Baseline tasks created by software installers and management agents, which legitimately create tasks, and exclude their command patterns.
- Alert louder when the task runs from a user-writable path (AppData, Temp, ProgramData) or references an interpreter.
Limitations
- Tasks created directly through the Task Scheduler COM API or by writing XML to the Tasks folder do not call schtasks.exe and are missed here.
- Remote task creation does not reveal the source host in this query.
Related queries
References
Last reviewed 2026-11-18.