Trying to make advance SingleInstance force Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Yatendra3192
Posts: 71
Joined: 10 Dec 2017, 06:57
Facebook: mr.nothingtolose

Trying to make advance SingleInstance force

08 Feb 2018, 09:41

Hi All,

I have a same script in different folders, when i run scripts one by one, they all started running, even though they have same name.

i think it's because of the nature of #SingleInstance force, It cant close the previous script with the same name if it's in the different folder.

I try to do that with the below script i found but it's not working can anyone tell me what i'm doing wrong here.

Code: [Select all] [Expand] [Download] (Test.ahk)GeSHi © Codebox Plus

User avatar
divanebaba
Posts: 626
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Trying to make advance SingleInstance force

08 Feb 2018, 10:02

If your script has a Gui, you can try this PostMessage, 0x111, 65307,,, NewAutoHotkeyScript.ahk.
I've tested with two scripts and when you look a bit how to match the filenames, it should solve your issue.

[Starklichtbirne IQ >> 250!!] Dank deutscher Lehrerempfehlung, nur Süperdepp und Hartz4-Bezieher, statt Abitürient und Einkommensbezieher.
[Strong light bulb IQ >> 250!!] Thanks to german teacher's recommendation, willful and welfare recipient, instead of high school graduate and moneymaker.

Entering high school for foreign children is not prohibited in GERMANY, it's only made nearly impossible by government.
Virtually the only way - visiting high school abroad.
Yatendra3192
Posts: 71
Joined: 10 Dec 2017, 06:57
Facebook: mr.nothingtolose

Re: Trying to make advance SingleInstance force

08 Feb 2018, 10:09

Sorry Divanebaba :( My scripts dose not have GUI they runs in the background. thank you so much for your support.
Yatendra3192
Posts: 71
Joined: 10 Dec 2017, 06:57
Facebook: mr.nothingtolose

Re: Trying to make advance SingleInstance force

08 Feb 2018, 11:35

I tried the link you gave Not able to make sense :roll:
User avatar
divanebaba
Posts: 626
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Trying to make advance SingleInstance force

08 Feb 2018, 15:48

Hi.

There is an nice example at this site. Look Example #5 at the bottom of the site.
Or look here for a bit modified version.

Code: [Select all] [Download] GeSHi © Codebox Plus

; Beispiel #5: Ermittelt eine Liste von allen laufenden Prozessen via COM.
Gui, +Caption +Resize MinSize550x150
Gui, Add, ListView, x2 y0 w400 h500 vLV, Prozessname|Befehlszeile
for Prozess in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process")
LV_Add("", Prozess.Name, Prozess.CommandLine)
Gui, Show,, Prozessliste
return

GuiSize:
GuiControl, move, LV, % " w" A_GuiWidth - 4 " h" A_GuiHeight - 16
return
As you can see, in second column there are the paths and filenames listet.
I tried to split the loop to get access to second column, but I failed.
Should be possible to identify a thread with same name with this example.
How to close, I don't know, because I get stucked by the for-loop.

But I think this could be a possible first step.
Maybe the professionals here have not so many problems like I and can show you better and faster way.

[Starklichtbirne IQ >> 250!!] Dank deutscher Lehrerempfehlung, nur Süperdepp und Hartz4-Bezieher, statt Abitürient und Einkommensbezieher.
[Strong light bulb IQ >> 250!!] Thanks to german teacher's recommendation, willful and welfare recipient, instead of high school graduate and moneymaker.

Entering high school for foreign children is not prohibited in GERMANY, it's only made nearly impossible by government.
Virtually the only way - visiting high school abroad.
Osprey
Posts: 293
Joined: 18 Nov 2017, 05:50

Re: Trying to make advance SingleInstance force

08 Feb 2018, 15:50

If I'm understanding your situation correctly, it's the same that I had and which I addressed with this little function:

Code: [Select all] [Download] GeSHi © Codebox Plus

; Check if a script of the same name is already running (from a different location) and, if so, close the older process
CheckProcess()
{
PID := DllCall("GetCurrentProcessId")
Process, Exist, %A_ScriptName%
If (ErrorLevel != PID)
Process, Close, %ErrorLevel%
}
Put that anywhere and then add CheckProcess() near the beginning (top) of your script.
lexikos
Posts: 5896
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Trying to make advance SingleInstance force

09 Feb 2018, 05:30

Yatendra3192 wrote:I try to do that with the below script i found but it's not working
Did you name the script Test.ahk? It works for me.
divanebaba wrote:If your script has a Gui, you can try this
Yatendra3192 wrote:Sorry Divanebaba :( My scripts dose not have GUI they runs in the background.
That script does not require a GUI. It posts a message to the script's main window, which every script has.
Yatendra3192
Posts: 71
Joined: 10 Dec 2017, 06:57
Facebook: mr.nothingtolose

Re: Trying to make advance SingleInstance force

09 Feb 2018, 13:55

lexikos wrote:
Yatendra3192 wrote:I try to do that with the below script i found but it's not working
Did you name the script Test.ahk? It works for me.
divanebaba wrote:If your script has a Gui, you can try this
Yatendra3192 wrote:Sorry Divanebaba :( My scripts dose not have GUI they runs in the background.
That script does not require a GUI. It posts a message to the script's main window, which every script has.


find the problem why my script not working

if script name in uppercase (Test.ahk) and under the script it's mentioned in lowercase (test.ahk) it will not work properly.

I don't know why but after fixing this it's working fine.
lexikos
Posts: 5896
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Trying to make advance SingleInstance force  Topic is solved

10 Feb 2018, 16:53

Window titles are case-sensitive.

Return to “Ask For Help”

Who is online

Users browsing this forum: mozart1000 and 42 guests