Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

DiscordLock (discordprioritylock)

A tiny Windows utility that pins Discord's process priority class to NORMAL and self-heals it if Discord ever escapes the lock.

By default Discord raises its own process to High priority on Windows, which can cause FPS drops in games and stutters. DiscordLock prevents Discord from ever raising its priority above Normal and continuously keeps it there.

How it works

DiscordLock.exe is a single ~800 KB static binary (one source file, discordlock.cpp). It does not launch Discord itself. Instead it runs as a persistent background watcher.

  1. Locked job object — On startup CreatePriorityJob() creates a job object and sets JOB_OBJECT_LIMIT_PRIORITY_CLASS with NORMAL_PRIORITY_CLASS. Any process assigned to the job is held at Normal priority by the OS.

  2. Watch loopmain() enters an infinite loop, sleeping 500 ms between checks (≈0% CPU impact).

  3. Detect & relaunchMonitorAndLock() walks all processes via CreateToolhelp32Snapshot. For every Discord.exe that is not already inside the locked job, it:

    • kills the unlocked process (KillAllDiscordProcesses()TerminateProcess),
    • waits 500 ms for Windows to release handles,
    • relaunches Discord through the installer stub so it attaches to the locked job (LaunchLockedDiscordUpdate.exe --processStart Discord.exe, created CREATE_SUSPENDED, then AssignProcessToJobObject + ResumeThread).

Processes that are already in the job are left untouched.

Build

Requires a C++17-capable compiler (tested with g++).

g++ -O2 -mwindows -static -static-libgcc -static-libstdc++ -o DiscordLock.exe DiscordLock.cpp

Flags:

  • -O2 — optimization
  • -mwindows — no console window
  • -static / -static-libgcc / -static-libstdc++ — fully self-contained binary

Usage

  1. Compile (see above).
  2. Run DiscordLock.exe.
  3. Launch Discord normally from your desktop/taskbar. DiscordLock detects it, attaches it to the locked job, and keeps it at Normal priority.

DiscordLock does not need to be started first — it waits for you to launch Discord.

Requirements / caveats

  • Windows only (uses Win32 job objects, Toolhelp snapshots).
  • Discord must be installed normally so that %LOCALAPPDATA%\Discord\Update.exe exists — the relaunch path invokes Update.exe --processStart Discord.exe. If that path is missing, Discord cannot be relaunched through the locked job.
  • Discord is terminated and relaunched on every cycle where it is found outside the job (e.g. after a crash, update, or manual launch that bypassed the lock). This is the "lock" cost: not CPU, but a kill/relaunch event.

Source layout

File Purpose
discordlock.cpp Entire program (one translation unit)
DiscordLock.exe Compiled binary (git-ignored)

Key functions in discordlock.cpp:

  • CreatePriorityJob() — build the Normal-priority job object.
  • KillAllDiscordProcesses() — terminate every Discord.exe.
  • LaunchLockedDiscord(HANDLE) — relaunch Discord attached to the job.
  • MonitorAndLock(HANDLE) — one scan/relaunch cycle.
  • main() — create job + persistent watch loop.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages