Skip to content

Instantly share code, notes, and snippets.

@cs127
Created August 8, 2025 08:34
Show Gist options
  • Save cs127/e6469ca6104851de56d3fd88619104da to your computer and use it in GitHub Desktop.
Save cs127/e6469ca6104851de56d3fd88619104da to your computer and use it in GitHub Desktop.
pizzablocker
#define WIN32_LEAN_AND_MEAN
#include <shlwapi.h>
#include <windows.h>
static const char* BLOCKED_WORDS [] =
{
"pizza",
"james",
NULL
};
static BOOL CALLBACK CloseIfHasWords
(
HWND hWnd,
LPARAM lParam
)
{
char** apszWords = (char**)lParam;
char szTitle [MAX_PATH];
unsigned int i;
GetWindowTextA(hWnd, szTitle, MAX_PATH);
for (i = 0; apszWords[i]; i++)
{
if (StrStrIA(szTitle, apszWords[i]))
{
DWORD dwPid = 0;
HANDLE hProcess;
GetWindowThreadProcessId(hWnd, &dwPid);
if (!dwPid) goto end;
hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwPid);
if (!hProcess) goto end;
TerminateProcess(hProcess, 1);
CloseHandle(hProcess);
}
}
end:
return TRUE;
}
int WINAPI WinMain
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
while (TRUE)
{
EnumWindows(CloseIfHasWords, (LPARAM)BLOCKED_WORDS);
Sleep(100);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment