Sign in to follow this  
Followers 0
plastix

Detect If Already Running...

17 posts in this topic

#1 ·  Posted (edited)

I have been trying (without success) to prevent more than a single copy of a given script running at any one time (compiled or otherwise).

The closest I have come is using AutoItWinSetTitle - and appending a timestamp (@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) to the window.

The application has a GUI, but this may be closed with the system tray waiting for re-activation. Thus, the title is "hidden".

Using AutoItSetOption("WinDetectHiddenText", 1) lets me detect the hidden window.

What I can't figure out is how to detect the number of windows (hidden or otherwise) so that the system can cycle through the title's to see if the script is already running with a different timestamp... I can't find any reference for a namespace etc that would enumerate the number of windows and allow me ot reference them... or a "next title" function... because often the first title match is the current script and doesn't necessarily mean another is running.

I'm sure I saw a link to a screenshot utility that mentioned a system of detecting if it is running... but the script is no longer in the archives.

TIA :)

Edited by plastix

Share this post


Link to post
Share on other sites



I have been trying (without success) to prevent more than a single copy of a given script running at any one time (compiled or otherwise).

The closest I have come is using AutoItWinSetTitle - and appending a timestamp (@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) to the window.

The application has a GUI, but this may be closed with the system tray waiting for re-activation. Thus, the title is "hidden".

Using AutoItSetOption("WinDetectHiddenText", 1) lets me detect the hidden window.

What I can't figure out is how to detect the number of windows (hidden or otherwise) so that the system can cycle through the title's to see if the script is already running with a different timestamp... I can't find any reference for a namespace etc that would enumerate the number of windows and allow me ot reference them... or a "next title" function... because often the first title match is the current script and doesn't necessarily mean another is running.

I'm sure I saw a link to a screenshot utility that mentioned a system of detecting if it is running... but the script is no longer in the archives.

TIA :)

Look at _Singleton() in the Beta help file.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I have been trying (without success) to prevent more than a single copy of a given script running at any one time (compiled or otherwise).

The closest I have come is using AutoItWinSetTitle - and appending a timestamp (@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC) to the window.

The application has a GUI, but this may be closed with the system tray waiting for re-activation. Thus, the title is "hidden".

Using AutoItSetOption("WinDetectHiddenText", 1) lets me detect the hidden window.

What I can't figure out is how to detect the number of windows (hidden or otherwise) so that the system can cycle through the title's to see if the script is already running with a different timestamp... I can't find any reference for a namespace etc that would enumerate the number of windows and allow me ot reference them... or a "next title" function... because often the first title match is the current script and doesn't necessarily mean another is running.

I'm sure I saw a link to a screenshot utility that mentioned a system of detecting if it is running... but the script is no longer in the archives.

TIA :)

yeah _Singleton() for limiting the number of instanciated copies of your script, but it sounds like you should look into WinList() too, not necessarily for what you're wanting it for (because singleton will take care of that issue) but just so you know about it.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

many thanks cameronsdad & CyberSlug.

both methods work nicely... i'll stick to the _Singleton() method... appreciate the heads up re: WinList()

Thanks again :)

Share this post


Link to post
Share on other sites

many thanks cameronsdad & CyberSlug.

both methods work nicely... i'll stick to the _Singleton() method... appreciate the heads up re: WinList()

Thanks again :)

no problem, always glad to help.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

no problem, always glad to help.

That's funny, I mentioned the _SingleTon() first... and I'm the only one that didn't get mentioned... :) (Finding rock to hide under)...

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

That's funny, I mentioned the _SingleTon() first... and I'm the only one that didn't get mentioned... :) (Finding rock to hide under)...

i actually noticed that too, but didn't say anything about it. happy belated birthday, man. how was your present?

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

i actually noticed that too, but didn't say anything about it. happy belated birthday, man. how was your present?

How can this close the first process and start a new process, like refreshing..? you know instead of closing itself if it's already open.

if _Singleton("test\test",1) = 0 Then
    Exit
EndIf
Edited by slightly_abnormal

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

What do you mean close the 'first' process. This is made to close the same process trying to start itself. So the first instance is never closed, only any extra instances are closed.

MHz, made a "restart" or "refresh" script last week.

Edit:

Example using MHz's code: http://www.autoitscript.com/forum/index.ph...ndpost&p=159442

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

What do you mean close the 'first' process. This is made to close the same process trying to start itself. So the first instance is never closed, only any extra instances are closed.

MHz, made a "restart" or "refresh" script last week.

Edit:

Example using MHz's code: http://www.autoitscript.com/forum/index.ph...ndpost&p=159442

i think i would have to laugh if i get a thanks for this and you don't ron.

If Not $CMDLINE[0] Then
    If UBound(ProcessList(@ScriptName)) > 2 Then Exit
ElseIf $CMDLINE[1] <> '/restart' Then
    Exit    
EndIf

$Main = GUICreate("Example", 140, 60,-1, -1)
$Button1 = GUICtrlCreateButton("Restart", 20, 10, 100, 40)

GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = - 3 Then Exit
    If $msg = $Button1 Then 
        Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart')
        Exit
    EndIf
WEnd

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

I mean, I have a script running, and then I start that same script it will close the script that was already running but keep the newly started one..

if _Singleton("test\test",1) = 0 Then

Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart')

EndIf

???

Share this post


Link to post
Share on other sites

I mean, I have a script running, and then I start that same script it will close the script that was already running but keep the newly started one..

if _Singleton("test\test",1) = 0 Then

Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart')

EndIf

???

causes it to reapear endlessly.. :)

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

causes it to reapear endlessly.. :)

You did "Compile" it first right?

Edit:

Actually now that I think about it, have you looked at the _SingleTon() UDF, it's preset to do something already...Try this code without _SingleTon()

If Not $CMDLINE[0] Then
    If UBound(ProcessList(@ScriptName)) > 2 Then Exit
ElseIf $CMDLINE[1] <> '/restart' Then
    Exit    
EndIf

;Placing this outside the loop, so you can see it's only generated when the script starts
Local $ShowTitle = ''
For $x = 1 To 10
    $ShowTitle = $ShowTitle & Chr(Random(65, 90, 1))
Next

While 1
    If UBound(ProcessList(@ScriptName)) > 2 Then
        If MsgBox(4, 'Restart', 'There was another instance, would you liket o restart?') == 6 Then
            Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart')
            Exit
        EndIf
    EndIf
    ToolTip('This EXE Self Title: ' & $ShowTitle, 0, 0)
    Sleep(10)
WEnd
Only Compile this code so you can see it working!

Edit 2:

Gave a better example... with the example above, the only way to change that title is with a new restart (you still need to compile it first). Watch as you try to open the .exe again, it will automatically restart and the title will change.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Well since you were on most of the evening 'slightly_abnormal', did the above example work (I know it works) but more so solve your issue?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Well since you were on most of the evening 'slightly_abnormal', did the above example work (I know it works) but more so solve your issue?

yes, thanks. I forgot to reply.

Share this post


Link to post
Share on other sites

This may be not entirely true

On line 1

If ProcesExists("AutoIt3.exe") Then
       EXIT
EndIf

It unfortunately also checks if ANY other scripts are launched.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0