Pcornel
Windows · Processes

Handles

Cheat sheet · https://pcornel.dk/topic.php?topic=3009

Back to the Topic

Answer

A handle is a value a process uses to refer to an object managed by Windows, such as a file, registry key, event, mutex, process, thread, token or section. The handle is meaningful in the context of the process handle table and carries granted access rights.

Remember

  • A handle value is process-relative; the same numeric value in another process can refer to a different object.
  • Open handles keep references to objects until they are closed/released.
  • Handles have access rights, so having a handle does not imply unrestricted access.
  • Some handles can be inherited by child processes when both creation and inheritance settings allow it.
  • A steadily increasing handle count can indicate a leak, but the object types and workload must be checked.

First checks

  • Get-Process | Sort CPU -Desc | Select -First 10 Name,Id,CPU,WS — top processes
  • Get-CimInstance Win32_Process -Filter "ProcessId=<pid>" | Select Name,ParentProcessId,CommandLine — command line and parent
  • tasklist /v — processes with user and status
  • taskkill /PID <pid> /T — stop a process tree

Verify in this order

process opens objects (files, keys, events) → handles in its table → closed when done

Where it usually breaks

First mismatch in definition/configuration → security context → service/task/process creation → runtime state → output/side effect → event/performance evidence; preserve identity/native error/pre-state before mutation.

Processes → Handles reference map

ItemMeaningEvidence boundary
Handle valueProcess-local referenceinterpret only with owning PID
Object typeFile/process/thread/event/etc.narrows what resource is referenced
Object nameNamed path/object when exposedlinks runtime reference to resource
Granted accessRights on the handlewhat operations this reference allows
Handle countAggregate process metrictrend/object mix needed before calling it a leak

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=3009

Confirmation

Confirm action

Continue?