I want to use the RtlSetProcessIsCritical function that sets a current process as critical but I really couldn't find a way to use it with Python. Here is the example of it in C :
#include <windows.h>
typedef VOID(_stdcall* RtlSetProcessIsCritical) (
IN BOOLEAN NewValue,
OUT PBOOLEAN OldValue,
IN BOOLEAN IsWinlogon);
BOOL ProcessIsCritical()
{
HANDLE hDLL;
RtlSetProcessIsCritical fSetCritical;
hDLL = LoadLibraryA("ntdll.dll");
if (hDLL != NULL)
{
(fSetCritical) = (RtlSetProcessIsCritical)GetProcAddress((HINSTANCE)hDLL, "RtlSetProcessIsCritical");
if (!fSetCritical) return 0;
fSetCritical(1, 0, 0);
return 1;
}
else
return 0;
}
Is there any way to make it work in Python?
Here is the link to an article that describes the RtlSetProcessIsCritical
function pretty good: https://www.codeproject.com/Articles/43405/Protecting-Your-Process-with-RtlSetProcessIsCriti
CodePudding user response:
Try to load ntdll.dll in python. Requires Pywin32 library.
import win32process
import win32api
import ctypes
from ctypes import *
ntdll = WinDLL("ntdll.dll")
ntdll.RtlSetProcessIsCritical(1,0,0)