Page 1 of 1

WinExist can't detect a running script.

Posted: 11 May 2024, 12:03
by alawsareps
I always get "error: NOT FOUND".

tried running both script as an administrator..
Image

Code: Select all

#Requires AutoHotkey v2.0

f1:: {

    DetectHiddenWindows(true)
    
    if WinExist("c:\Users\jethr\OneDrive\Desktop\closeme.ahk ahk_class AutoHotkey"){
        msgbox("script exist")
    }   

    else {
        msgbox("error: NOT FOUND")
    }
    
}


Re: WinExist can't detect a running script.  Topic is solved

Posted: 11 May 2024, 13:20
by mikeyww
The following worked here. If your script is in a different directory, it will fail. Finding out is easy: open the script's window. This does not require admin privileges, so test without it.

Learning the value returned by WinExist does not require any If statement.

Code: Select all

#Requires AutoHotkey v2.0

F1:: {
 DetectHiddenWindows True
 MsgBox WinExist(A_Desktop '\closeme.ahk ahk_class AutoHotkey')
}

F2:: {  ; Get list of running scripts
 DetectHiddenWindows True
 out := ''
 n   := 0
 For hWnd in WinGetList('ahk_class AutoHotkey')
  If !InStr(title := WinGetTitle(hWnd), '\launcher.ahk') {
   out .= RegExReplace(title, ' - AutoHotkey v.+') '`n`n'
   n++
  }
 MsgBox Trim(out, '`n'), 'Running scripts (N=' n ')', 'Iconi'
}