Toggle Running state of a Process; Suspend and resume

Post your working scripts, libraries and tools for AHK v1.1 and older
AladinZ
Posts: 2
Joined: 30 Sep 2017, 13:20

Toggle Running state of a Process; Suspend and resume

11 Dec 2018, 22:53

I Looked for a ready-made script for this purpose, However, I could not. This script bellow is a combination of two scripts I found. Replace "ReplaceMe.exe" with the target process name. CTRL + B will Toggle between suspending, and resuming the target process.

Code: Select all

Control & B::


if (toggle := !toggle) {
	

Process_Suspend("ReplaceMe.exe")

;MsgBox, blender.exe suspended




Process_Suspend(PID_or_Name){

    PID := (InStr(PID_or_Name,".")) ? ProcExist(PID_or_Name) : PID_or_Name

    h:=DllCall("OpenProcess", "uInt", 0x1F0FFF, "Int", 0, "Int", pid)

    If !h   

        Return -1

    DllCall("ntdll.dll\NtSuspendProcess", "Int", h)

    DllCall("CloseHandle", "Int", h)

}

} else {


Process_Resume("blender.exe")

;MsgBox, blender.exe resumed



Process_Resume(PID_or_Name){

    PID := (InStr(PID_or_Name,".")) ? ProcExist(PID_or_Name) : PID_or_Name

    h:=DllCall("OpenProcess", "uInt", 0x1F0FFF, "Int", 0, "Int", pid)

    If !h   

        Return -1

    DllCall("ntdll.dll\NtResumeProcess", "Int", h)

    DllCall("CloseHandle", "Int", h)

}



ProcExist(PID_or_Name=""){

    Process, Exist, % (PID_or_Name="") ? DllCall("GetCurrentProcessID") : PID_or_Name

    Return Errorlevel

}
}
return
bunnxr
Posts: 2
Joined: 30 Jan 2020, 05:41

Re: Toggle Running state of a Process; Suspend and resume

02 Feb 2020, 10:20

That's exactly what I was looking for, thanks mate, I would like to request you something, if it is possible to suspend the Active Application window (any application that's running in the foreground), to be suspended by a single hotkey and then resuming it by another hotkey. That'd be great.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Rohwedder and 225 guests