Skip to content
medium severityMicrosoft Defender XDR

Detect Windows service creation (KQL)

A new Windows service runs code automatically, often as SYSTEM, which makes service creation a powerful persistence and privilege path — and the mechanism behind tools like PsExec. This DeviceProcessEvents query matches sc.exe create and PowerShell New-Service, showing the service's binary path on the command line.

Review the binPath: services pointing at scripts, user-writable folders or living-off-the-land binaries deserve immediate attention.

The query

DeviceProcessEvents
| where Timestamp > ago(7d)
| where (FileName =~ "sc.exe" and ProcessCommandLine has "create")
    or (FileName in~ ("powershell.exe", "pwsh.exe") and ProcessCommandLine has "New-Service")
| project Timestamp, DeviceName, AccountName,
          InitiatingProcessFileName, InitiatingProcessCommandLine, ProcessCommandLine
| sort by Timestamp desc

Line-by-line explanation

  • FileName =~ "sc.exe" and ProcessCommandLine has "create"

    sc.exe create is the native command to register a new service and its binary path.

  • FileName in~ ("powershell.exe", "pwsh.exe") and ProcessCommandLine has "New-Service"

    New-Service is the PowerShell equivalent; including it closes a common evasion of sc.exe-only rules.

  • project ... ProcessCommandLine

    Keeps the command line so the service name and binPath — what the service will execute — are visible for triage.

Required tables and columns

  • FileNameThe image used to create the service (sc.exe or a PowerShell host).
  • ProcessCommandLineCommand line with the service name and binary path (binPath).
  • InitiatingProcessFileNameParent process; a remote tool like PsExec shows a distinctive chain.
  • AccountNameAccount creating the service, typically privileged.

MITRE ATT&CK mapping

Tuning and false positives

  • Baseline services created by legitimate installers, EDR and management agents, and exclude their service names or binPaths.
  • Raise severity when binPath lives in a user-writable directory or invokes cmd/powershell with an encoded or download command.

Limitations

  • Services created directly through the Service Control Manager API or by writing the registry do not call sc.exe and are missed; pair with DeviceRegistryEvents on the Services key for fuller coverage.

References

Last reviewed 2026-11-18.