Skip to content

Instantly share code, notes, and snippets.

@imba-tjd
Last active January 13, 2026 02:56
Show Gist options
  • Select an option

  • Save imba-tjd/9e8a4869d7ed5263a65e759997b53c6a to your computer and use it in GitHub Desktop.

Select an option

Save imba-tjd/9e8a4869d7ed5263a65e759997b53c6a to your computer and use it in GitHub Desktop.
Show warning when battery die
// gcc battery.c -o battery.exe -Os -mwindows -Wl,--as-needed -s -nostdlib -luser32 -lkernel32 -march=native
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <psapi.h>
static SYSTEM_POWER_STATUS status;
int _main() {
SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
EmptyWorkingSet(GetCurrentProcess());
while (1) {
GetSystemPowerStatus(&status);
if (status.BatteryLifePercent < 50)
MessageBox(NULL, "Battery below 50%", "Battery Warning", MB_SYSTEMMODAL | MB_ICONWARNING);
Sleep(10 * 60 * 1000); // every 10m
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment