Opening a file in lock mode can have some side effects. What if the user aborted the app from the Task-Manager? The file still stays locked.
Use the Windows API's Mutex flags, instead (this works):
[External functions]
FUNCTION ulong CreateMutexA (ulong lpMutexAttributes, boolean bInitialOwner, REF string lpszName) LIBRARY "kernel32.dll"
FUNCTION long GetLastError() LIBRARY "kernel32.dll"
////////////////////////////////////////////////////
FUNCTION boolean of_IsRunning()
////////////////////////////////////////////////////
// USAGE:
//
// IF of_isRunning THEN
// MessageBox("Oops!", "App already running!"

// END IF
////////////////////////////////////////////////////
constant ulong ERROR_ALREADY_EXISTS = 183
constant ulong SUCCESSFUL_EXECUTION = 0
//
ulong lul_mutex
ulong lpsa
ulong lul_last_error
boolean lb_ret = FALSE
//
IF NOT (Handle(GetApplication()) = 0) THEN
lul_mutex = CreateMutexA(lpsa, FALSE, as_appname)
lul_last_error = GetLastError()
lb_ret = NOT (lul_last_error = SUCCESSFUL_EXECUTION)
END IF
//
RETURN lb_ret
Hope this helps...
---
PowerObject!
-----------------------------------------
PowerBuilder / PFC Developers' Group