Best way to check if process and win exists in one line

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Yanush Kartov

Best way to check if process and win exists in one line

22 Apr 2018, 10:13

What am I doing wrong here?? I want to check if my game is running and if the window is not exists,

Code: Select all

If ProcessExist("spongeball.exe")  && !WinExist ("ahk_exe spongeball.exe")
	MsgBox Remember to turn off


ProcessExist(Name){
	Process,Exist,%Name%
	return Errorlevel
}
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Best way to check if process and win exists in one line

22 Apr 2018, 11:30

since Porcess, Exist and WinExist when used with "ahk_exe" are effectively the same, u got this going on:

Code: Select all

A | (A ∧ ¬A)
--|---------
F |    F
T |    F
unreachable code, what are contradictions for 200, alex?
Last edited by swagfag on 22 Apr 2018, 13:59, edited 1 time in total.
Yanush Kartov

Re: Best way to check if process and win exists in one line

22 Apr 2018, 12:19

swagfag wrote:since Porcess, Exist and WinExist when used with "ahk_exe" are effectively the same, u got this going on:

Code: Select all

A | (A ∧ ¬A)
--|---------
F |    F
T |    F
unreachable code, what are contradictions for 200, alex?
a process can exist without its window being shown. So back to my question - how can I check if a process exists BUT its window is not exist
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Best way to check if process and win exists in one line

22 Apr 2018, 14:00

youre right i overlooked that

Code: Select all

If ProcessExist("svchost.exe")  && !WinExist("ahk_exe svchost.exe")
	MsgBox Remember to turn off


ProcessExist(Name){
	Process,Exist,%Name%
	return Errorlevel
}
the following works for me, the only thing ive modified from your original script was deleting the space between WinExist (), this is a syntax error and doesnt call the function
Yanush Kartov

Re: Best way to check if process and win exists in one line

22 Apr 2018, 18:11

swagfag wrote:youre right i overlooked that

Code: Select all

If ProcessExist("svchost.exe")  && !WinExist("ahk_exe svchost.exe")
	MsgBox Remember to turn off


ProcessExist(Name){
	Process,Exist,%Name%
	return Errorlevel
}
the following works for me, the only thing ive modified from your original script was deleting the space between WinExist (), this is a syntax error and doesnt call the function
i see it works with svchost, however, with my game and even iexplore.exe it does not work, for example, if i have the process hidden (winhide) it will still see it as winexist :headwall:
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Best way to check if process and win exists in one line

23 Apr 2018, 01:41

I hid Internet Explorer, but still found a window with class 'Alternate Owner'. I set SetTitleMatchMode to RegEx, to make it look for a window that had a window title of at least one character, and then it didn't find any windows.

Code: Select all

q::
DetectHiddenWindows, Off
MsgBox, % hWnd := WinExist("ahk_exe iexplore.exe")
WinGetTitle, vWinTitle, % "ahk_id " hWnd
WinGetClass, vWinClass, % "ahk_id " hWnd ;Alternate Owner
MsgBox, % vWinTitle "`r`n" vWinClass

SetTitleMatchMode, RegEx
MsgBox, % hWnd := WinExist(". ahk_exe iexplore.exe")
WinGetTitle, vWinTitle, % "ahk_id " hWnd
WinGetClass, vWinClass, % "ahk_id " hWnd
MsgBox, % vWinTitle "`r`n" vWinClass
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Yanush Kartov

Re: Best way to check if process and win exists in one line

23 Apr 2018, 03:06

jeeswg wrote:I hid Internet Explorer, but still found a window with class 'Alternate Owner'. I set SetTitleMatchMode to RegEx, to make it look for a window that had a window title of at least one character, and then it didn't find any windows.

Code: Select all

q::
DetectHiddenWindows, Off
MsgBox, % hWnd := WinExist("ahk_exe iexplore.exe")
WinGetTitle, vWinTitle, % "ahk_id " hWnd
WinGetClass, vWinClass, % "ahk_id " hWnd ;Alternate Owner
MsgBox, % vWinTitle "`r`n" vWinClass

SetTitleMatchMode, RegEx
MsgBox, % hWnd := WinExist(". ahk_exe iexplore.exe")
WinGetTitle, vWinTitle, % "ahk_id " hWnd
WinGetClass, vWinClass, % "ahk_id " hWnd
MsgBox, % vWinTitle "`r`n" vWinClass
return
I used your code to try to build a test. When I run the script it launched hidden IE. Now when I hit q I would like for it to tell me if there IE hidden or not.

Can you help me fix the code for that please?

Code: Select all

pwb := ComObjCreate("InternetExplorer.Application")
pwb.Visible := False
pwb.Navigate("https://www.google.com")
;while pwb.ReadyState != 4
	sleep, 15000
pwb.quit()
Return

q::
DetectHiddenWindows, Off
MsgBox, % hWnd := WinExist("ahk_exe iexplore.exe")
WinGetTitle, vWinTitle, % "ahk_id " hWnd
WinGetClass, vWinClass, % "ahk_id " hWnd ;Alternate Owner
MsgBox, % vWinTitle "`r`n" vWinClass 


SetTitleMatchMode, RegEx
MsgBox, % hWnd := WinExist(". ahk_exe iexplore.exe") 
WinGetTitle, vWinTitle, % "ahk_id " hWnd
WinGetClass, vWinClass, % "ahk_id " hWnd
MsgBox, % vWinTitle "`r`n" vWinClass 


return
esc::ExitApp
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Best way to check if process and win exists in one line

23 Apr 2018, 06:58

Here's some example code.

Code: Select all

q:: ;check if IE window exists
pwb := ComObjCreate("InternetExplorer.Application")
pwb.Visible := 0 ;False
hWnd := pwb.HWND
DetectHiddenWindows, On
MsgBox, % WinExist("ahk_id " hWnd)
DetectHiddenWindows, Off
;pwb.Visible := -1 ;True
pwb.Quit()
pwb := ""

WinWaitClose, % "ahk_id " hWnd
SoundBeep

DetectHiddenWindows, On
MsgBox, % WinExist("ahk_id " hWnd)
DetectHiddenWindows, Off
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], prototype_zero and 271 guests