Results 1 to 8 of 8

Thread: [RESOLVED] Pause Process Execution

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Resolved [RESOLVED] Pause Process Execution

    I've seen some third party applications pause the execution of a process and then enable that process later.

    As far as I can tell, there is no managed way to do this, so I've been looking at unmanaged ways via an API. I couldn't find any specific information on it, but I figured there must be something.

    Does anyone know a method to complete my task or an API I could research?

    Any information is appreciated.

    Thanks
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Pause Process Execution

    Perhaps you are looking for SuspendThread and ResumeThread APIs? The following is VB6.
    Code:
    Private Declare Function ResumeThread Lib "kernel32.dll" ( _
                    ByVal hThread As Long) As Long
    Private Declare Function SuspendThread Lib "kernel32.dll" ( _
                    ByVal hThread As Long) As Long
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Pause Process Execution

    Moved To API Section

  4. #4

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Pause Process Execution

    Quote Originally Posted by dee-u View Post
    Perhaps you are looking for SuspendThread and ResumeThread APIs? The following is VB6.
    Code:
    Private Declare Function ResumeThread Lib "kernel32.dll" ( _
                    ByVal hThread As Long) As Long
    Private Declare Function SuspendThread Lib "kernel32.dll" ( _
                    ByVal hThread As Long) As Long
    Thanks. I'll look into them
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  5. #5
    Lively Member agent_007's Avatar
    Join Date
    Jan 2010
    Posts
    93

    Re: Pause Process Execution

    u can use sleep api
    The Sleep function suspends the execution of the current thread for a specified interval.
    Code:
    Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
    sleep 5000 ' sleep for 5 secs

  6. #6

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Pause Process Execution

    Quote Originally Posted by agent_007 View Post
    u can use sleep api
    The Sleep function suspends the execution of the current thread for a specified interval.
    Code:
    Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
    sleep 5000 ' sleep for 5 secs
    I don't want to pause the process for a set amount of time. I want it to be paused until the User decides to resume it.

    I've been looking into the first two functions mentioned and it seems I need to get the Thread handle of the process and pass it as an argument to the function. The problem with that, is that I can't seem to figure out how to get the thread handle :P

    I passed the Process Handle to the function, but that didn't work. So, I'm still working on finding the thread handle.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  7. #7

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Pause Process Execution

    So I looked around Google a bit more and found a post in C#:

    http://stackoverflow.com/questions/7...d-process-in-c

    That code apparently worked for them, but I can't seem to get it to work for me. I translated the code and I would appreciate any help into figuring it out.

    APIs and Flags:

    vb Code:
    1. Declare Function SuspendThread Lib "kernel32.dll" (ByVal hThread As IntPtr) As UInteger
    2.     Declare Function ResumeThread Lib "kernel32.dll" (ByVal hThread As IntPtr) As UInteger
    3.  
    4.     Public Enum ThreadAccess As Integer
    5.         TERMINATE = 1
    6.         SUSPEND_RESUME = 2
    7.         GET_CONTEXT = 8
    8.         SET_CONTEXT = 16
    9.         SET_INFORMATION = 32
    10.         QUERY_INFORMATION = 64
    11.         SET_THREAD_TOKEN = 128
    12.         IMPERSONATE = 256
    13.         DIRECT_IMPERSONATION = 512
    14.     End Enum
    15.  
    16. Declare Function OpenThread Lib "kernel32.dll" (ByVal dwDesiredAccess As ThreadAccess, ByVal bInheritHandle As Boolean, ByVal dwThreadId As UInteger) As IntPtr

    Suspend Thread Code:

    vb Code:
    1. Dim pid As Integer = Int32.Parse(lvwProcess.SelectedItems(0).SubItems(1).Text)
    2.         Dim p As Process = Process.GetProcessById(pid)
    3.  
    4. If lvwProcess.SelectedItems.Count = 0 Then
    5.      Else
    6.  
    7.          If (p.ProcessName = String.Empty) Then
    8.          Else
    9.             For Each pThread As ProcessThread In p.Threads
    10.                     Dim pOpenThread As IntPtr = OpenThread(ThreadAccess.SUSPEND_RESUME, False, CType(p.Id, UInteger))
    11.                     If (pOpenThread = IntPtr.Zero) Then
    12.                         Exit For
    13.                     End If
    14.                     SuspendThread(pOpenThread)
    15.              Next
    16.         End If
    17. End If
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  8. #8

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Pause Process Execution

    It turns out I was passing the ID of the process to the API and not the ID of the thread. I have it fixed, though.

    Thanks again
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width