Hi All,
I have 100's exact replica of AHK Script on different location (like for eg. D:\Network Drive\30\Timetracker.ahk and D:\Network Drive\31\Timetracker.ahk) when i run script 31 when 30 is already running or if start 30 when 31 is running, they both start running.
I want to exit previous instances running with the name Timetracker.ahk when i run Timetracker.ahk
Duplicate script able to run from different location how to stop it Topic is solved
-
- Posts: 89
- Joined: 10 Dec 2017, 06:57
Re: Duplicate script able to run from different location how to stop it
Have you tried adding the following to the top of the scripts?
I'm not sure if that applies to the same script running from different locations, but give it a try.
If it doesn't work, you can try adding the following to the top:
Code: Select all
#SingeInstance Force
If it doesn't work, you can try adding the following to the top:
Code: Select all
Process, Close, %A_ScriptName%
-
- Posts: 89
- Joined: 10 Dec 2017, 06:57
Re: Duplicate script able to run from different location how to stop it
Hi Osprey
I tried that but this did not resolve the issue but thanks for taking a time out to reply appreciate our help
I tried that but this did not resolve the issue but thanks for taking a time out to reply appreciate our help
Re: Duplicate script able to run from different location how to stop it
I just realized that Process, Close works with compiled scripts, but not uncompiled ones. To use it, you'd have to change it to, say, Process, Close, AutoHotkeyU32.exe, or whichever executable you have set to run your scripts.
-
- Posts: 89
- Joined: 10 Dec 2017, 06:57
Re: Duplicate script able to run from different location how to stop it
if i have the same script on different folders and run them they will run separately
what i'm looking for is something that check if script with the same name Timetracker.ahk already running if yes then close that one and start the new one i asked for and it doesn't get effected by different folder location of script
what i'm looking for is something that check if script with the same name Timetracker.ahk already running if yes then close that one and start the new one i asked for and it doesn't get effected by different folder location of script
-
- Posts: 89
- Joined: 10 Dec 2017, 06:57
Re: Duplicate script able to run from different location how to stop it
the script i'm running to check this has the same name so isn't it contradict the Process, Close, condition
Re: Duplicate script able to run from different location how to stop it
- I would suspect that something like this script would come in useful at some point.
- You can check the window titles to see if a particular script is open, and use WinClose to close a script.
- The built-in variable, A_ScriptHwnd, might be useful, to compare it with hWnd.
- You can check the window titles to see if a particular script is open, and use WinClose to close a script.
- The built-in variable, A_ScriptHwnd, might be useful, to compare it with hWnd.
Code: Select all
q:: ;list open AutoHotkey scripts
DetectHiddenWindows, On
WinGet, vWinList, List, ahk_class AutoHotkey
vOutput := ""
Loop, % vWinList
{
hWnd := vWinList%A_Index%
WinGetTitle, vWinTitle, % "ahk_id " hWnd
;WinGetClass, vWinClass, % "ahk_id " hWnd
;WinGet, vPID, PID, % "ahk_id " hWnd
vOutput .= hWnd " " vWinTitle "`r`n"
}
MsgBox, % vOutput
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
-
- Posts: 89
- Joined: 10 Dec 2017, 06:57
Re: Duplicate script able to run from different location how to stop it
Hi Jeeswg,
It's a nice idea but require to run an additional script , what i'm looking for is something like instant-force who can close the previous same name script even though it's store in different location, and can be embedded into a script it self,
It's a nice idea but require to run an additional script , what i'm looking for is something like instant-force who can close the previous same name script even though it's store in different location, and can be embedded into a script it self,
Re: Duplicate script able to run from different location how to stop it
How many instances of Timetracker.ahk run at the same time?
If it's just one, you could do this. Put these lines at the top of the script.
If it's just one, you could do this. Put these lines at the top of the script.
Code: Select all
DetectHiddenWindows, On
SetTitleMatchMode, 2
if hWnd := WinExist("Timetracker.ahk ahk_class AutoHotkey")
WinClose, % "ahk_id " hWnd
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
-
- Posts: 89
- Joined: 10 Dec 2017, 06:57
Re: Duplicate script able to run from different location how to stop it
i just need to run just one, but if it is already running it has to close the previous one.
i tried your code but it's closes itself from running or i think it's doing what we told it to do closing itself.
i tried your code but it's closes itself from running or i think it's doing what we told it to do closing itself.
Re: Duplicate script able to run from different location how to stop it Topic is solved
Oh gosh, you're right. A simple fix to my script above would be to use WinSetTitle twice, to temporarily change its name to something else, but here's a proper script:
Code: Select all
q:: ;close other AHK scripts with same name
DetectHiddenWindows, On
SetTitleMatchMode, 2
WinGet, vWinList, List, \Timetracker.ahk ahk_class AutoHotkey
Loop, % vWinList
{
hWnd := vWinList%A_Index%
;WinGetTitle, vWinTitle, % "ahk_id " hWnd
;WinGetClass, vWinClass, % "ahk_id " hWnd
;WinGet, vPID, PID, % "ahk_id " hWnd
if !(hWnd = A_ScriptHwnd)
WinClose, % "ahk_id " hWnd
}
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
-
- Posts: 89
- Joined: 10 Dec 2017, 06:57
Re: Duplicate script able to run from different location how to stop it
Got It! it's working grate. thank you so much for all your help and efforts on solving this jeeswg. greatly appreciated.
Who is online
Users browsing this forum: Descolada and 305 guests