Skip to main content

Overview

The PowerToys Runner is the main executable (PowerToys.exe) that serves as the host process for all PowerToys modules. It manages module lifecycle, hotkey registration, the system tray icon, and communication with the Settings UI.

Core Responsibilities

Initialization Sequence

The Runner follows a specific initialization order to ensure all components are ready before modules are enabled.

1. Process Initialization

Reference: src/runner/main.cpp:181

2. Tray Icon Startup

Reference: doc/devdocs/core/runner.md:37-65

3. Module Loading

Reference: src/runner/powertoy_module.cpp:13-24

4. Settings Application

Reference: doc/devdocs/core/runner.md:130-138

5. Keyboard Hook Registration

Reference: doc/devdocs/core/runner.md:120-128

System Tray Icon

The system tray icon is the primary UI element of the Runner, providing quick access to settings and module controls.

Implementation

Reference: doc/devdocs/core/runner.md:49-56, src/runner/tray_icon.cpp

Window Procedure

Reference: doc/devdocs/core/runner.md:57-61

Tray Icon Actions

Left Click - Quick Access Flyout:
Reference: doc/devdocs/core/runner.md:66-68, doc/devdocs/core/runner.md:103-112 Double Click - Dashboard:
Reference: doc/devdocs/core/runner.md:71-74 Right Click - Context Menu: The context menu is defined in resource files:
Reference: doc/devdocs/core/runner.md:114-119

Module Management

Module Discovery

The Runner scans for module DLLs in the modules/ directory:
Note: WinUI 3 applications are located in a separate WinUI3Apps/ folder to avoid DLL conflicts. Reference: doc/devdocs/core/runner.md:17-19

Module Lifecycle

Reference: src/runner/powertoy_module.h, src/runner/powertoy_module.cpp

Centralized Keyboard Hook

The Runner uses a low-level keyboard hook to intercept hotkey presses for all modules. This centralized approach prevents performance issues from multiple hooks.

Implementation

Performance Optimizations:
  1. Early Exit on PowerToys-Generated Input
    • Uses dwExtraInfo flag to ignore synthetic keystrokes
    • Prevents infinite loops and unnecessary processing
  2. No Key Press Detection
    • Returns immediately if no keys are actually pressed
    • Avoids processing modifier-only events
  3. Metadata Caching
    • Caches hotkey information to avoid repeated lookups
    • Uses efficient data structures for fast matching
Important: The hook handler must execute very quickly as it’s called on every keystroke system-wide. Reference: doc/devdocs/core/runner.md:120-128

Hotkey Registration

Modules report their hotkeys to the Runner, which registers them with the centralized keyboard hook.

Hotkey Collection

Reference: src/modules/interface/powertoy_module_interface.h:111-124

Hotkey Conflict Detection

The Settings UI checks for hotkey conflicts across modules:
  1. Each module implements get_hotkeys() or GetHotkeyEx()
  2. Settings UI collects all hotkeys via Runner IPC
  3. Conflicts are displayed in the Settings UI with warnings
  4. User can resolve conflicts by changing hotkeys
Reference: doc/devdocs/core/settings/settings-implementation.md:74-108

IPC with Settings UI

The Runner communicates with the Settings UI process via Windows Named Pipes using a bidirectional JSON protocol.

Pipe Initialization

Reference: doc/devdocs/core/runner.md:76-91, src/runner/settings_window.cpp

Message Types

Runner → Settings UI:
Settings UI → Runner:
Reference: doc/devdocs/core/settings/runner-ipc.md:16-20

Message Processing

Reference: doc/devdocs/core/runner.md:157, src/runner/tray_icon.cpp:157

Update Management

The Runner handles automatic update checking and installation.

Update Checking

Reference: doc/devdocs/core/runner.md:196

Update Installation

When the user approves an update from the Settings UI:
  1. Download installer to temp directory
  2. Verify digital signature
  3. Close all PowerToys processes
  4. Launch installer with elevation
  5. Exit Runner (installer will restart after completion)
Reference: src/runner/UpdateUtils.cpp

Key Source Files

Next Steps

Module Interface

Learn how to implement a PowerToys module

Settings System

Understand the settings architecture and IPC

Architecture Overview

High-level system architecture

Common Libraries

Shared utilities and helper functions