Jump to content

_Singleton


Recommended Posts

Q3. How can I prevent more than one copy of my script from running at once / detect another copy of my script running?

If you simply want know if another copy is running, you can use code similar to the next example:

CODE: AutoIt

#include <Misc.au3>

If _Singleton("MyScriptName", 1) Then

; We know the script is already running. Let the user know.

MsgBox(0, "Script Name", "This script is already running. Using multiple copies of this script at the same breaks the [(UltimaCoder)] License!")

Exit

Endif

I have tried it but for me dont work.

I need a singol istance.

My script name is "ServerPorter"

Link to comment
Share on other sites

I have already tried in all mode, but it never work with me, can be a problem with vista?

i have made this function:

Func CheckPID()

$list = ProcessList("ServerPorter.exe")
for $i = 1 to $list[0][0]
    if  $list[$i][1] <> @AutoItPID then
        msgbox(4096, $list[$i][0], "ServerPorter.exe is already executed!!")
        Sleep(5000)
        exit 0
    EndIf
next

EndFunc
Link to comment
Share on other sites

This is another example of how to do that from the help file (FAQ section)

; Place at the top of your script

$g_szVersion = "My Script 1.1"

If WinExists($g_szVersion) Then Exit ; It's already running

AutoItWinSetTitle($g_szVersion)

; Rest of your script goes here

Try it out

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

I have already tried in all mode, but it never work with me, can be a problem with vista?

i have made this function:

Func CheckPID()

$list = ProcessList("ServerPorter.exe")
for $i = 1 to $list[0][0]
    if  $list[$i][1] <> @AutoItPID then
        msgbox(4096, $list[$i][0], "ServerPorter.exe is already executed!!")
        Sleep(5000)
        exit 0
    EndIf
next

EndFunc
If your running Vista it doesn't hurt to put #RequireAdmin at the top of your code. Whenever I am making scripts that will be ran on a Vista system I just automatically put it in, it has made some work that should have otherwise been fine but wouldn't work.

Vista's security is a hassle for admins as well as many other things.

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