LPARAMETERS tname LOCAL jreturn jreturn=.f. *!* *-- CODE COMMENTS FROM ED RAUGH ON THE UT, modified slightly - returns .t. or .f. *!* Forum: Thread ID: 409058 *!* Category: Message ID: 409114 *!* Title: Re: A New Twist On Is App Running *!* *!* This has the advantage that it derives it's Event name from the executable, and if you do forget to issue a *!* CloseHandle(), it still releases the Event object without bleeding, and the Event object completely *!* disappears automagically when no remaining Event refs exist. *!* CLOSE ALL will release the Event. You can use the Event for synchronizing several processes or thread using *!* WaitForSingleObject() to wait on someone to 'raise' the event if you need some sort of event monitoring. *!* Works under all OS versions I tested - not checked under Win95, but does work on Win98 and ME, as well as NT and 2K. *!* You can use any name you want if linking to the app's initial program doesn't work for you - I chose that because it's easy to get right, and presumably you want to block other instances of the app you're starting. *!* EMail: EdR@edrauh.com *!* "See, the sun is going down..." *!* "No, the horizon is moving up!" *!* - Firesign Theater DECLARE INTEGER CreateEvent IN WIN32API ; INTEGER lpEventAttributes, ; SHORT bManualReset, ; SHORT bInitialState, ; STRING @ lpName DECLARE INTEGER GetLastError IN Win32API DECLARE CloseHandle IN Win32API INTEGER hObject nEh = CreateEvent(0,0,1, tname + '.EVENT') IF GetLastError() = 183 OR nEh = 0 * There's an instance running already (183) or the Event can't be defined * So don't do it; do release the handle, since it's harmless and should * be done rather than relying on Windows to clean up after itself =CloseHandle(nEh) jreturn=.t. ENDIF RETURN jreturn>Hi Stacy and All,
DECLARE INTEGER CreateEvent IN WIN32API ; >>> INTEGER lpEventAttributes, ; >>> SHORT bManualReset, ; >>> SHORT bInitialState, ; >>> STRING @ lpName >>>DECLARE INTEGER GetLastError IN Win32API >>>DECLARE CloseHandle IN Win32API INTEGER hObject >>>nEh = CreateEvent(0,0,1, PROGRAM(0) + '.EVENT') >>>IF GetLastError() = 183 OR nEh = 0 >>> * There's an instance running already (183) or the Event can't be defined >>> * So don't do it; do release the handle, since it's harmless and should >>> * be done rather than relying on Windows to clean up after itself >>> =CloseHandle(nEh) >>> QUIT >>>ENDIF >>> >>>* While shutting down, issue: >>>=CloseHandle(nEh)>>>