Help checking if process suspended

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
nathan323
Posts: 44
Joined: 31 Jan 2016, 02:53
Location: Australia

Help checking if process suspended

20 Aug 2017, 23:17

I have found this: https://autohotkey.com/board/topic/1138 ... suspended/

Code: Select all

IsProcessSuspended(pid) {
    For thread in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Thread WHERE ProcessHandle = " pid)
        If (thread.ThreadWaitReason != 5)
            Return False
    Return True
}

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
When running the examples given (with cemu.exe for process), I get this error:
Error at line 2 in #include file "C:\Program Files\AutoHotkey\Lib\IsProcessSuspended.ahk".
Line Text:     For thread in ComObjGet("winmgmts").ExecQuery("Select * from Win32_Thread WHERE ProcessHandle = ...
Error: This line does not contain a recognized action.
I read the documentation for ComObjGet, I'm not sure where I'm going wrong..

Win7 64
AHK 1.1.26.01
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Help checking if process suspended

21 Aug 2017, 10:23

I'm guessing here, but maybe it needs the process handle, not it's ID. Try adding this (from the link):

Code: Select all

hProcess := DllCall("OpenProcess", "UInt", 0x1F0FFF, "Int", 0, "Int", pid)
then send "hProcess"...

Code: Select all

IsProcessSuspended(hProcess)
That's just from reading the code; it could be typed in wrong.
nathan323
Posts: 44
Joined: 31 Jan 2016, 02:53
Location: Australia

Re: Help checking if process suspended

21 Aug 2017, 20:39

Ok thanks. I added the lines and swapped all mention of PID with hProcess. Now I get:

Error at line 4 in #include file "C:\Program Files\AutoHotkey\Lib\IsProcessSuspended.ahk".
Line Text:         If (thread.ThreadWaitReason != 5)
Error: This line does not contain a recognized action.
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Help checking if process suspended

22 Aug 2017, 08:49

Alright. Instead of relying on my limited knowledge alone, I tested the script you posted at the top. It works. So, ignore my response, it is wrong.
Copy this into an AHK script, run it, then press F2.

Code: Select all

IsProcessSuspended(pid) {
    For thread in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Thread WHERE ProcessHandle = " pid)
        If (thread.ThreadWaitReason != 5)
            Return False
    Return True
}

F2::
    Process, Exist, firefox.exe
    ID := ErrorLevel
    test := IsProcessSuspended(ID)
	MsgBox % test
If you don't have "firefox.exe" (from the Firefox browser), replace it with the process of whatever browser you use.
I ran that script with Firefox open and it returned that the process was not suspended (which it wasn't).
So, the script is good. Something's wrong on your end.
nathan323
Posts: 44
Joined: 31 Jan 2016, 02:53
Location: Australia

Re: Help checking if process suspended

23 Aug 2017, 01:34

Yep it all runs fine for me now too, without changing anything. Couple of restarts later, must've been something buggy going on.

Thanks for your help :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, Joey5 and 241 guests