Page 1 of 1

Close unwanted windows when they appear

Posted: 19 Feb 2018, 05:43
by Bluscream

Code: Select all

#SingleInstance, Force
#NoEnv
#Warn
SetWorkingDir %A_ScriptDir%

titles := "Cheat Engine 6.7"
classes := "ClassAdvert, MainFrameInstall"
binaries := "clover.exe"

Loop
{
	WinWait, , , , .
    WinGetTitle, title
    TrayTip, found window %title%
    if title in %titles%
        WinClose, %title%
        continue
    WinGetClass, class
    if class in %classes%
        WinClose, ahk_class %class%
        continue
    WinGet, exe, ProcessName
    if exe in %binaries%
        MsgBox, %exe%
        WinClose, ahk_exe %exe%
        continue
}
Can anyone help me getting this to work?

Re: Close unwanted windows when they appear

Posted: 19 Feb 2018, 06:11
by BoBo

Code: Select all

#Persistent
#SingleInstance, Force

SetTimer, Kill,% 1000 * 1 ; check once every second
Return

Kill:
   Process, Exist, clover.exe
   If ErrorLevel
      PID := ErrorLevel
   Process, Close,% "ahk_PID " . PID
   Return
Not tested.

Re: Close unwanted windows when they appear

Posted: 19 Feb 2018, 19:10
by Bluscream
A timer is exactly what i don't want, i really want it to only go through the loop when a new window opens

i tried LastFound now but that doesn't seem to change anything:

Code: Select all

#SingleInstance, Force
; #NoTrayIcon
#NoEnv
#Warn
SetWorkingDir %A_ScriptDir%

titles := "Cheat Engine 6.7"
classes := "ClassAdvert, MainFrameInstall"
binaries := "clover.exe"

Loop
{
	WinWait, , , , .
    WinGetTitle, title, LastFound
    TrayTip, found window %title%
    if title in %titles%
        WinClose, %title%
        continue
    WinGetClass, class, LastFound
    if class in %classes%
        WinClose, ahk_class %class%
        continue
    WinGet, exe, ProcessName
    if exe in %binaries%
        MsgBox, %exe%
        WinClose, ahk_exe %exe%
        continue
}
BTW: the binaries are not so important, i can use ProcessLasso for that

Re: Close unwanted windows when they appear

Posted: 19 Feb 2018, 20:28
by Bluscream
Okay, i think https://gist.github.com/Bluscream/119f0 ... nclose-ahk is good enough for me. Thanks anyway :)