Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Functions] Freeze processes: SuspendProcess() ResumeProcess() IsProcessSuspended()


  • Please log in to reply
1 reply to this topic
Bruttosozialprodukt
  • Members
  • 457 posts
  • Last active: Oct 18 2015 08:47 AM
  • Joined: 20 Oct 2012

I just wanted to share a few very useful functions with you.
The following functions allow you to freeze and resume a process and get the current suspension state.

This can be useful when you want to analyze a process/window or if you simply want to get more performance out of your machine.

For example you could freeze processes that take a long time to start and are using a lot of CPU power even while you don't use them... like games for example.

So here you go:

SuspendProcess(pid) {
    hProcess := DllCall("OpenProcess", "UInt", 0x1F0FFF, "Int", 0, "Int", pid)
    If (hProcess) {
        DllCall("ntdll.dll\NtSuspendProcess", "Int", hProcess)
        DllCall("CloseHandle", "Int", hProcess)
    }
}
ResumeProcess(pid) {
    hProcess := DllCall("OpenProcess", "UInt", 0x1F0FFF, "Int", 0, "Int", pid)
    If (hProcess) {
        DllCall("ntdll.dll\NtResumeProcess", "Int", hProcess)
        DllCall("CloseHandle", "Int", hProcess)
    }
}
IsProcessSuspended(pid) {
    For thread in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Thread WHERE ProcessHandle = " pid)
        If (thread.ThreadWaitReason != 5)
            Return False
    Return True
}

Usage example:

F2::
    Process, Exist, hh.exe
    pid := ErrorLevel
    If (!IsProcessSuspended(pid))
        SuspendProcess(pid)
Return

F3::
    Process, Exist, hh.exe
    pid := ErrorLevel
    If (IsProcessSuspended(pid))
        ResumeProcess(pid)
Return


iDrug
  • Members
  • 389 posts
  • Last active: Oct 11 2015 09:24 PM
  • Joined: 13 Oct 2009
This is awesome! STOLEN.