amidy Posted February 23, 2009 Share Posted February 23, 2009 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 More sharing options...
Authenticity Posted February 23, 2009 Share Posted February 23, 2009 You better compile the script and preform a process check in the header so each instance shuts itself if it's name is already in the returning array of the ProcessList() function. Link to comment Share on other sites More sharing options...
exodius Posted February 23, 2009 Share Posted February 23, 2009 Or just lookup the _Singleton command in the Help file. Link to comment Share on other sites More sharing options...
myspacee Posted February 23, 2009 Share Posted February 23, 2009 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 More sharing options...
jvanegmond Posted February 23, 2009 Share Posted February 23, 2009 Or just lookup the _Singleton command in the Help file.This.Just saying "This." because this is really what you need. Listing other processes and such is not a good alternative. github.com/jvanegmond Link to comment Share on other sites More sharing options...
FireFox Posted February 23, 2009 Share Posted February 23, 2009 Mutex is another way and the function takes only 3lines Cheers, FireFox. Link to comment Share on other sites More sharing options...
FireFox Posted February 23, 2009 Share Posted February 23, 2009 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 More sharing options...
Ascend4nt Posted February 23, 2009 Share Posted February 23, 2009 (edited) 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 February 23, 2009 by ascendant My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
FireFox Posted February 23, 2009 Share Posted February 23, 2009 (edited) @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 February 23, 2009 by FireFox Link to comment Share on other sites More sharing options...
Mojo Posted March 11, 2009 Share Posted March 11, 2009 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 More sharing options...
jvanegmond Posted March 11, 2009 Share Posted March 11, 2009 Works fine for me. AutoIt v3.3.0.0 Windows XP SP3. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Mojo Posted March 11, 2009 Share Posted March 11, 2009 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now