Sign in to follow this  
Followers 0
Knight

One Instance of Script at a time.

10 posts in this topic

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.

Share this post


Link to post
Share on other sites



Maybe

If UBound(ProcessList(@ScriptName)) > 2 Then
    MsgBox(262208, "* NOTE * ", "Welcome to AutoIt 1-2-3 was already running  ", 5)
    Exit
EndIf

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Welcome

i like your addition too!

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

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


[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

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

Share this post


Link to post
Share on other sites

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.


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

Share this post


Link to post
Share on other sites

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


[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 want to know if it is possible to pass the command line parameter to the already running programme, but not duplicate to run. Thank you

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