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

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
alawsareps
Posts: 26
Joined: 20 Jul 2016, 09:28

WinExist can't detect a running script.

Post by alawsareps » 11 May 2024, 12:03

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")
    }
    
}

Attachments
image.png
image.png (91.07 KiB) Viewed 267 times

User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

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

Post by mikeyww » 11 May 2024, 13:20

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'
}

Post Reply

Return to “Ask for Help (v2)”