Code snippet:
#include <windows.h> #include <ntdll.h> int WINAPI iWinMain() { #ifdef _WIN64 LPWSTR captionMsg = L"64-bit Application"; #else LPWSTR captionMsg = L"32-bit Application"; #endif BOOLEAN oldValue; LPWSTR finishedMsg = L"Failed!"; if (RtlAdjustPrivilege( SE_DEBUG_PRIVILEGE, TRUE, FALSE, &oldValue) == STATUS_SUCCESS) { if (RtlSetProcessIsCritical( TRUE, NULL, FALSE) == STATUS_SUCCESS) { MessageBoxW( NULL, L"I'm critical process don't kill me!", captionMsg, MB_ICONINFORMATION); if (RtlSetProcessIsCritical( FALSE, NULL, FALSE) == STATUS_SUCCESS) { MessageBoxW( NULL, L"Now, I'm normal process!", captionMsg, MB_ICONINFORMATION); finishedMsg = L"Finished!"; } } } MessageBoxW( NULL, finishedMsg, captionMsg, MB_ICONINFORMATION); return 0; }
Source:
http://www.mediafire.com/download/0k5ti3rnppcd8db/RtlSetProcessIsCritical.rar