"Hibernate" a process

0

I want to be able to hibernate a process, make it inactive, not run, but when you remove that state go back to where it was just before hibernating it.

I have searched the internet for methods to do this, but I have not found anything. I tried the function SuspendThread , but it's not what I want.

Can I do what I want? What would it be like in VB.Net ?

The function of SuspendThread that I tried is blocking the process, but it continues to occupy memory.

Code:

Public Enum ThreadAccess As Integer
    TERMINATE = (&H1)
    SUSPEND_RESUME = (&H2)
    GET_CONTEXT = (&H8)
    SET_CONTEXT = (&H10)
    SET_INFORMATION = (&H20)
    QUERY_INFORMATION = (&H40)
    SET_THREAD_TOKEN = (&H80)
    IMPERSONATE = (&H100)
    DIRECT_IMPERSONATION = (&H200)
End Enum

Private Declare Function OpenThread Lib "kernel32.dll" (ByVal dwDesiredAccess As ThreadAccess, ByVal bInheritHandle As Boolean, ByVal dwThreadId As UInteger) As IntPtr
Private Declare Function SuspendThread Lib "kernel32.dll" (ByVal hThread As IntPtr) As UInteger
Private Declare Function ResumeThread Lib "kernel32.dll" (ByVal hThread As IntPtr) As UInteger
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hHandle As IntPtr) As Boolean
Public Sub SuspendProcess(ByVal process As System.Diagnostics.Process)
    For Each t As ProcessThread In process.Threads
        Dim th As IntPtr'

        th = OpenThread(ThreadAccess.SUSPEND_RESUME, False, t.Id)
        If th <> IntPtr.Zero Then
            SuspendThread(th)
            CloseHandle(th)
        End If
    Next
End Sub

Public Sub ResumeProcess(ByVal process As System.Diagnostics.Process)
    For Each t As ProcessThread In process.Threads
        Dim th As IntPtr

        th = OpenThread(ThreadAccess.SUSPEND_RESUME, False, t.Id)
        If th <> IntPtr.Zero Then
            ResumeThread(th)
            CloseHandle(th)
        End If
    Next
End Sub'

Is it possible to do it by calling an API or whatever a process does not occupy any resources , but nevertheless when calling another API em>, the process is back in the state it was in just before calling the first API .

    
asked by Hackeitos 26.03.2017 в 12:54
source

1 answer

0

You can evaluate maybe applying Windows Workflow Foundation for this. What a priori you indicate is a State Machine or state machine. WF use SQL Server as persistence to store your suspended status. You can see more information at Windows Workflow Foundation Programming

    
answered by 27.03.2017 в 22:33