How to create an endless process?

Asked

Viewed 91 times

4

Simple question, how do I make my application process to be "unstoppable" by the system? I want when a user tries to close the application to appear the message "Access denied", and when it forces the termination of the error in the kernel CRITICAL_PROCESS_DIED. That’s what happens to the process wininit.exe 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. You can programmatically make the app can close smoothly and another time can be endless?

1 answer

2

I found this class in another OR 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.