Jump to content

Stopping a script from running if its already running.


amidy
 Share

Recommended Posts

Hello all!

I'm using a IR based remote to Trigger a script, and start two programs and it tends to trigger the script twice or three times causing one of the apps to crash.

So I'm wondering if there is a If, or a command that i could put in place on t he script to make sure that a previous instance of the script is running for it to close itself.

Thanks in advance!

Link to comment
Share on other sites

using this in my script.

;////////////////////////////////////////////////////////////////////
;//   controllo esistenza di una sola sessione - chiudo le altre !
;////////////////////////////////////////////////////////////////////
$list = ProcessList(@ScriptName)
for $i = 1 to $list[0][0]
    if $i > 1 Then
        msgbox(0, "ClipME", "Puoi lanciare una sola sessione di " & @ScriptName, 1)
        ProcessClose($list[$i][1])
    EndIf
next

m.

Link to comment
Share on other sites

Without function :

$hMutex = DllCall('kernel32.dll', 'hwnd', 'OpenMutex', 'int', 0x1F0001, 'int', False, 'str', @ScriptName)
If $hMutex[0] Then Exit MsgBox(16, 'Warning - Error !', 'Only one instance of ' & @ScriptName & ' is allowed !')
DllCall('kernel32.dll', 'hwnd', 'CreateMutex', 'int', 0, 'int', False, 'str', @ScriptName)oÝ÷ Ùh­û§rب«­¢+Ù%}5ÕÑà¡MÉ¥ÁÑ9µ¤Q¡¸á¥Ð5Í  ½à ÄØ°Ìäí]ɹ¥¹ÌÌìÌäì°Ìäí=¹±ä½¹¥¹Íѹ½ÌäìµÀìMÉ¥ÁÑ9µµÀìÌäì¥Ì±±½ÝÌÌìÌäì¤()Õ¹}5ÕÑà ¤($ÀÌØí¡5ÕÑàô±±
±° Ìäí­É¹°Ìȹ±°Ìäì°Ìäí¡Ý¹Ìäì°Ìäí=Á¹5ÕÑàÌäì°Ìäí¥¹ÐÌäì°ÁàÅÀÀÀÄ°Ìäí¥¹ÐÌä찱ͰÌäíÍÑÈÌäì°MÉ¥ÁÑ9µ¤(%%ÀÌØí¡5ÕÑálÁtQ¡¸IÑÕɸÄ(%±±
±° Ìäí­É¹°Ìȹ±°Ìäì°Ìäí¡Ý¹Ìäì°Ìäí
ÉÑ5ÕÑàÌäì°Ìäí¥¹ÐÌäì°À°Ìäí¥¹ÐÌä찱ͰÌäíÍÑÈÌäì°MÉ¥ÁÑ9µ¤(%IÑÕɸÀ)¹Õ¹ìôôÐí}5ÕÑà

Cheers, FireFox.

Link to comment
Share on other sites

Nice! Small and easy to use. Might want to add an @error check in there before you try to return the array though, since as I understood it DllCall doesn't return an array when it fails?

By the way, this doesn't require admin privileges does it?

Thanks

*by the way, _Singleton does the same thing with ignoring errors and returning an array element. I thought that was supposed to be fixed per the changes History.. well at least the _WinAPI functions were fixed..

Edited by ascendant
Link to comment
Share on other sites

@ascendant

I dont think its useful to add IsArray function because the DllCall 'always' work except when the dll is different or doesnt exists, but in this case im not sure that the os is working well :)

Cheers, FireFox.

Edited by FireFox
Link to comment
Share on other sites

  • 3 weeks later...

Hi guys,

_Singleton is not working correctly, is it?

I'm using AutoIt 3.3.0.0 on Windows XP SP3.

Could you try it and let me (us) know if it still works for you?

Try this for example

#include <Misc.au3>
_Singleton("EnterSomeUniqueStringForYourScript1223456blabla")

MsgBox(0,"test","Test - keep this open and try to start the exe again!")
Exit

thanks, cya

You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time. Abraham Lincoln - http://www.ae911truth.org/ - http://www.freedocumentaries.org/
Link to comment
Share on other sites

Works fine for me. AutoIt v3.3.0.0 Windows XP SP3.

Oh, that's weird. Thanks mate.

Now I know where I'll have to look. Maybe Kaspersky or .Net or so interferes.

I checked the return values and instead of the expected 183 the GetLastError returns 87.

Rasim's Mutex() works just fine though.

Maybe one of the AutoIt Gods around here knows why that happens.

I'll post the solution/problem if I can figure it out. Someone else might have this problem one day or another.

greetz

You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time. Abraham Lincoln - http://www.ae911truth.org/ - http://www.freedocumentaries.org/
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...