Created
December 13, 2023 01:27
-
-
Save StrikerX3/cf3e7a27421887f49041a31fa5ea56bd to your computer and use it in GitHub Desktop.
List all critical processes on Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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