How to create an endless process?

4

Simple question, how do I make my application process "unstoppable" by the system? I want when a user tries to close the application the message "Access is denied" appears, and when it forces the kernel to terminate the CRITICAL_PROCESS_DIED kernel error. This is what happens with the wininit.exe process by the CMD:

C:\> taskkill /im wininit.exe
ERRO: o processo "wininit.exe" com PID 532 não pôde ser finalizado.
Razão: Acesso negado.

Not even the WinInit process is displayed in the task manager. Can you programmatically make the application close without any problems and another time be endless?

    
asked by anonymous 07.02.2016 / 00:50

1 answer

2

I found this class in another OS question:

Public Class CriticalProcessInformationProcessor
    <DllImport("ntdll.dll", SetLastError:=True)>
    Private Shared Function NtSetInformationProcess(hProcess As IntPtr, processInformationClass As Integer, ByRef processInformation As Integer, processInformationLength As Integer) As Integer
    End Function
    Public Shared Sub EnableCriticalProcess()
        Dim isCritical As Integer = 1
        ' we want this to be a Critical Process
        Dim BreakOnTermination As Integer = &H1D
        ' value for BreakOnTermination (flag)
        Process.EnterDebugMode()
        'acquire Debug Privileges
        ' setting the BreakOnTermination = 1 for the current process
        NtSetInformationProcess(Process.GetCurrentProcess().Handle, BreakOnTermination, isCritical, 4)
    End Sub
    Public Shared Sub DisableCriticalProcess()
        Dim isCritical As Integer = 0
        ' we want this to be a Critical Process
        Dim BreakOnTermination As Integer = &H1D
        ' value for BreakOnTermination (flag)
        Process.EnterDebugMode()
        'acquire Debug Privileges
        ' setting the BreakOnTermination = 1 for the current process
        NtSetInformationProcess(Process.GetCurrentProcess().Handle, BreakOnTermination, isCritical, 4)
    End Sub
End Class
    
07.02.2016 / 01:20