count total instances of running script Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Sam_
Posts: 106
Joined: 20 Mar 2014, 20:24

count total instances of running script

18 Oct 2017, 13:39

When multiple instances of a script are running (via the #SingleInstance, Off directive), how can a script count how many instances are currently running?
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: count total instances of running script  Topic is solved

18 Oct 2017, 16:22

Probably WinGet, var, list, ahk_exe autohotkey.exe with DetectHiddenWindows, On, and then parsing that list for the name of the script when using WinGetTitle; see Example #2 at bottom of the WinGet documentation. Count the number of matches.
Sam_
Posts: 106
Joined: 20 Mar 2014, 20:24

Re: count total instances of running script

19 Oct 2017, 17:35

Ah yes, that is exactly what I was looking for. Thank you, @Exaskryz!

This does the trick nicely:

Code: Select all

DetectHiddenWindows, On
SetTitleMatchMode, 2
WinGet, ThreadCount, list, part_of_title ahk_class AutoHotkey
MsgBox % ThreadCount

Return to “Ask For Help”

Who is online

Users browsing this forum: batman3891, jappagtakhan, Odlanir, scriptingatwork and 160 guests