A rather old topic, but here's a VERY simple solution:
Don't close the Gui the script creates. Close the Systray ICON. It's title is (1) the script's path appended with (2) a dash, a space, "AutoHokey", a space and the ahk version number. So here is what I use:
; STOP an active AHK script
; The script name, just the filename, is passed as a parm.
; Note: The scripts' windows are HIDDEN!!!. DETECTHIDDENWINDOWS must be ON!
SetTitleMatchMode 2 ; titles must contain specified text
b := 1
Param:= %b% ; Get parameter 1.
wintitle = c:\users\Joey\Documents\autohotkey_scripts\%param%.ahk
winget, winid, id, %wintitle% - AutoHotkey
winclose , ahk_id %winid%
Of course, if you like to be more exact, the wintitle variable could also have the ahk version number and then you could use SetTitleMatchMode 3. But, why bother?