Detect registry Run key persistence (KQL)
The registry Run and RunOnce keys launch programs automatically at logon, which makes them one of the oldest and most common persistence locations on Windows. This DeviceRegistryEvents query matches value sets and key creations under the Run, RunOnce, RunServices, user shell folders and Winlogon paths, and shows the process that made the change along with the value written.
The written data is the payload path, so you can judge quickly whether an autostart entry is legitimate software or a dropped binary.
The query
DeviceRegistryEvents
| where Timestamp > ago(7d)
| where ActionType in ("RegistryValueSet", "RegistryKeyCreated")
| where RegistryKey has_any (
@"\CurrentVersion\Run",
@"\CurrentVersion\RunOnce",
@"\CurrentVersion\RunServices",
@"\CurrentVersion\Explorer\User Shell Folders",
@"\Winlogon")
| project Timestamp, DeviceName,
InitiatingProcessAccountName, InitiatingProcessFileName,
ActionType, RegistryKey, RegistryValueName, RegistryValueData
| sort by Timestamp descLine-by-line explanation
| where ActionType in ("RegistryValueSet", "RegistryKeyCreated")Keeps value writes and key creations — the operations that add an autostart entry — and ignores reads and deletes.
| where RegistryKey has_any (@"\CurrentVersion\Run", @"\Winlogon", ...)Matches the autostart paths; the @ verbatim strings let the backslashes be written literally without escaping.
project ... RegistryValueName, RegistryValueDataRegistryValueData holds the command or binary path that will run at logon — the key detail for triage.
Required tables and columns
ActionTypeThe registry operation; RegistryValueSet or RegistryKeyCreated here.RegistryKeyThe full key path, matched against the autostart locations.RegistryValueDataThe value written — the program or command set to run automatically.InitiatingProcessFileNameThe process that wrote the autostart entry.
MITRE ATT&CK mapping
Tuning and false positives
- Baseline the Run-key writes made by your standard software and updaters, then alert on new or unexpected value names and data paths.
- Raise severity when RegistryValueData points to AppData, Temp or ProgramData, or invokes a script interpreter.
Limitations
- Covers the listed autostart keys only; there are many other persistence registry locations (services, IFEO, COM hijacks) worth separate queries.
- Writes to HKCU vs HKLM both appear; distinguish them from RegistryKey when scoping by privilege.
Related queries
References
Last reviewed 2026-11-18.