>>>Hi All,
>>>
>>>How would I write code(s) to allow only one instance of the application to be executed? (check and prevent execution) Any suggestions or ideas is very appreciated.
>>>
>>>TIA
>>
>>
>>* Entr
>>if IsAppRunning(Application.ServerName)
>>*...
>>endif
>>
>>Function IsAppRunning
>> Lparameters tcSemaphoreName
>> Local hsem, lpszSemName
>> #Define ERROR_ALREADY_EXISTS 183
>> Declare Integer GetLastError In win32API
>> Declare Integer CreateSemaphore In WIN32API ;
>> string @ lpSemaphoreAttributes, ;
>> LONG lInitialCount, ;
>> LONG lMaximumCount, ;
>> string @ lpName
>> hsem = CreateSemaphore(0,0,1,tcSemaphoreName)
>> Return (hsem # 0 And GetLastError() == ERROR_ALREADY_EXISTS)
>>
Cetin
>
>Hi Cetin,
>you have found a code that with the semaphore, active the application that has created it?
>
>
>IF hsem # 0 And GetLastError() == ERROR_ALREADY_EXISTS
> * samaphore => ProcessId => WHANDLE => SetForegroundWindow(WHANDLE)
>ENDIF
>
>
>I wan't use FindWindow because it is mistaken.
>
>Thanks
>Fabio
Fabio,
It finds the application no matter if it has a visual representation or not (or even invoked from IDE for testing - IOW you uniquely mark an 'application' not the window hosting it).
Are you asking how to activate its window if any? If so I've to find my code that collects all processes and their related window handles but for that as I remember I needed to also create a FLL (VFP not supporting callback functions).
Cetin