Jump to content

One Instance of Script at a time.


Recommended Posts

It seems simple enough, and I have no idea how I haven't figured it out. I must be missing something big :o

I need to check if the script is already running after compilation. In other words, I don't want duplicate scripts (compiled) running at the same time.

Link to comment
Share on other sites

Thank you very much! Never would of thought of that lol..

I did however, make this tiny change :o

If UBound(ProcessList(@ScriptName)) > 2 Then
    WinActivate($Window)
    Exit
EndIf
Edited by Knight
Link to comment
Share on other sites

  • Moderators

If you have Beta, you can use _Singleton() in your files... .au3 / .a3x / or .exe (check out the Beta helpfile)

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

If you have Beta, you can use _Singleton() in your files... .au3 / .a3x / or .exe (check out the Beta helpfile)

I have seen that... but with the includes its just short of 400 lines of code added rather than the 4 above

( unless you are going to use the Misc.au3 include for one of the other Functions )

8)

NEWHeader1.png

Link to comment
Share on other sites

  • Moderators

Not so many... I just put the function in manually...

SingleRun('Make my own title for this semaphore')
Func SingleRun($semaphore)
    Local $ERROR_ALREADY_EXISTS = 183
    DllCall("kernel32.dll", "int", "CreateSemaphore", "int", 0, "long", 1, "long", 1, "str", $semaphore)
    Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
    If $lastError[0] = $ERROR_ALREADY_EXISTS Then Exit - 1
EndFunc
This one was made by Valik, it's the one I use.. not the one in the Help File.

With yours, all someone would have to do is rename the .exe to run another copy.

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 used that for the Welcome to Autoit... not caring if another exe was ran

this is XPClean Menu

; check if process already exists
$g_szVersion = "My XP Cleaner"
If WinExists($g_szVersion) Then
    MouseMove(500,5)
    MsgBox(64, "* NOTE * ", "*XPClean Menu* was already running  ", 5)
    SoundPlay ($Sound_lnk,1)
    Exit; It's already running
EndIf
AutoItWinSetTitle($g_szVersion)

this is for AuoIt-ITS

$G_SZVERSION = "Autoit ITS Connection Center*   ver " & @AutoItVersion
If WinExists($G_SZVERSION) Then Exit; It's already running
AutoItWinSetTitle($G_SZVERSION)

3 lines... and no other exe will run

8)

8)

NEWHeader1.png

Link to comment
Share on other sites

  • Moderators

:o

Well... not to say they would have access to it... but:

WinSetTitle("Autoit ITS Connection Center", "", "Something Else")

Your way would work, but... IMHO, I think it's better to have the failsafe internally that can't be changed externally

Both options are good 'To a point'.

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

  • 3 months later...

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