Skip to content

Instantly share code, notes, and snippets.

@StrikerX3
Created December 13, 2023 01:27
Show Gist options
  • Save StrikerX3/cf3e7a27421887f49041a31fa5ea56bd to your computer and use it in GitHub Desktop.
Save StrikerX3/cf3e7a27421887f49041a31fa5ea56bd to your computer and use it in GitHub Desktop.
List all critical processes on Windows
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <psapi.h>
void PrintProcessNameAndID(DWORD processID) {
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processID);
if (NULL != hProcess) {
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
DWORD size = sizeof(szProcessName) / sizeof(TCHAR);
QueryFullProcessImageName(hProcess, 0, szProcessName, &size);
BOOL isProcessCritical = FALSE;
if (IsProcessCritical(hProcess, &isProcessCritical) && isProcessCritical) {
_tprintf(TEXT("%s (PID: %u)\n"), szProcessName, processID);
}
CloseHandle(hProcess);
}
}
int main() {
DWORD aProcesses[1024], cbNeeded, cProcesses;
if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded)) {
return 1;
}
cProcesses = cbNeeded / sizeof(DWORD);
for (unsigned int i = 0; i < cProcesses; i++) {
if (aProcesses[i] != 0) {
PrintProcessNameAndID(aProcesses[i]);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment