Jump to content

Detect If Already Running...


Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

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.

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.

Link to comment
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.
Link to comment
Share on other sites

  • Moderators

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)...

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
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
Link to comment
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.. :)

Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
Share on other sites

  • Moderators

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?

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...