1
Files
autoPriority/README.md
T
lzrdblzzrd 565b751195 Rewrite game mode: two-pass scan, priority restoration, LimitedInformation access
- Use PROCESS_QUERY_LIMITED_INFORMATION instead of PROCESS_QUERY_INFORMATION
  to open processes (fixes Access Denied for KeePassXC, HD-Player, etc.)
- Separate query handle from set handle: trySetPrio reopens with
  PROCESS_SET_INFORMATION only when needed
- Two-pass scan: pass 1 collects RSS and detects game processes,
  pass 2 applies priorities with correct hasGame state
- Game mode saves original priorities in gameSaved map, restores them
  on GAME MODE OFF (not just NORMAL)
- Demote ALL non-game processes to IDLE in game mode (not just promoted)
- 50ms delay between priority changes for smooth transitions
- Replace isAlive/procName with pidMap from allProcs snapshot
- Replace mutex/MessageBox single-instance with killOtherInstances
- Defaults: -mem=512M, -game-mem=4G
- Fix double CloseHandle and handle leak in trySetPrio
- Update README with new defaults and game mode restoration behavior
2026-06-22 17:24:21 +03:00

3.5 KiB

autoPriority

Monitors process memory usage on Windows and automatically adjusts CPU priority: promotes memory-heavy processes to HIGH and demotes everything else to NORMAL. Optionally enters Game Mode when a process exceeds a higher threshold, boosting it to HIGH and setting all other processes to IDLE.

Windows only.

How it works

Normal mode

Every scan interval the program iterates over all running processes:

RSS vs -mem Current priority Action
≥ threshold anything except HIGH → HIGH (logged as PROMOTE)
≥ threshold already HIGH skip
< threshold ABOVE_NORMAL, HIGH, or REALTIME → NORMAL (logged as DEMOTE)
< threshold NORMAL, BELOW_NORMAL, or IDLE skip

Game mode (-game-mem)

When any process reaches or exceeds the -game-mem threshold:

  1. That process → HIGH (logged as GAME)
  2. All other processes → IDLE
  3. Log: GAME MODE ON

When all such processes close:

  1. All processes that were demoted during game mode are restored to their original priority (logged as RESTORE)
  2. GAME MODE OFF logged
  3. Normal mode resumes — priorities recalculated by -mem rules

If SetPriorityClass or OpenProcess fails for a process (e.g., anti-cheat protection, system processes), the process is added to an in-memory exclusion list and never touched again (logged as BLOCK). When the process exits, it is automatically removed from the list.

On shutdown, all processes are restored: game-mode demoted processes to their saved original priority, promoted and game processes to NORMAL.

Build

Requires Go 1.26+.

# Standard build (with console window)
go build -o autopriority.exe .

# Background build (no console, minimal size)
go build -ldflags="-H windowsgui -s -w" -o autopriority.exe .

Usage

autopriority [flags]
Flag Default Description
-mem 512M Memory threshold (e.g. 512M, 1G, 2048M)
-game-mem 4G Game threshold (e.g. 3G, 4G). Must be > -mem. 0 = disabled
-interval 1 minute Scan interval (min 10s)
-dry-run false Log only, don't change priority

Examples:

# Run with 1 GB threshold, scanning every 30 seconds
autopriority -mem=1G -interval=30s

# Run with defaults (512M threshold, 4G game threshold)
autopriority

# Game mode: normal threshold 512M, game threshold 4G
autopriority -mem=512M -game-mem=4G

# Dry run — log decisions without changing anything
autopriority -dry-run

Log

Log is always written to %TEMP%\autopriority.log. A new log file is created on each run (previous log is deleted).

Log entries:

Prefix Meaning
PROMOTE Priority raised to HIGH (normal mode)
DEMOTE Priority lowered to NORMAL (normal mode)
GAME Process set to HIGH or IDLE (game mode)
GAME MODE ON Game mode activated
GAME MODE OFF Game mode deactivated — processes restored
BLOCK OpenProcess or SetPriorityClass failed; process added to exclusion list
RESTORE Process restored to original/saved priority (game mode exit or shutdown)
SKIP RESTORE PID reused by a different process; restore skipped
[DRY-RUN] Would change priority (dry-run mode)

Auto-start

Open Win+R, type shell:startup, and press Enter. Then place a shortcut to autopriority.exe in the folder that opens.

Dependencies

None. Uses only Windows API (kernel32, psapi) via raw syscall.