vfp8 - detect other copies of app running

vfp8 - detect other copies of app running

Post by Jerem » Thu, 30 Oct 2003 04:27:06


My user has a bad habit of starting her program twice, and then having
errors on the second copy & not noticing what happened. Can I prevent this?

Jeremy
 
 
 

vfp8 - detect other copies of app running

Post by Leem » Thu, 30 Oct 2003 06:43:40

Hi Jeremy:

Go to www.universalthread.com, click on the Download icon and choose VFP as
eh product. Search for "Run only one instance of an application." The file
is called Oneinst.zip with a Download ID of 9329.

I hope this helps.

This posting is provided "AS IS" with no warranties, and confers no rights.

Sincerely,
Microsoft FoxPro Technical Support
Lee Mitchell

*-- VFP8 HAS ARRIVED!! --*
Read about all the new features of VFP8 here:
http://www.yqcomputer.com/
Purchase VFP8 here:
http://www.yqcomputer.com/

Keep an eye on the product lifecycle for Visual FoxPro here:
http://www.yqcomputer.com/ ;[ln];lifeprodv
- VFP5 Mainstream Support retired June 30th, 2003
- VFP6 Mainstream Support retires Sept. 30th, 2003


this?

 
 
 

vfp8 - detect other copies of app running

Post by Eric den D » Thu, 30 Oct 2003 09:01:15

Hello, Jeremy!
You wrote on Tue, 28 Oct 2003 11:27:06 -0800:

J> My user has a bad habit of starting her program twice, and then having
J> errors on the second copy & not noticing what happened. Can I prevent
J> this?

I've been using using the following code for a couple of years in my main
prg. Note that you might not like the use of the _screen.caption in the
code. All my apps have a unique _screen.caption; something that may not be
the case with your apps so my might need to change it.

<vfp_code>
IF NOT AppMutex()
QUIT
ELSE
* Proceed
ENDIF

FUNCTION AppMutex
DECLARE INTEGER CreateMutex IN WIN32API INTEGER, INTEGER, STRING @
DECLARE INTEGER CloseHandle IN WIN32API INTEGER
DECLARE INTEGER GetLastError IN WIN32API
DECLARE INTEGER SetProp IN WIN32API INTEGER, STRING @, INTEGER
DECLARE INTEGER GetProp IN WIN32API INTEGER, STRING @
DECLARE INTEGER RemoveProp IN WIN32API INTEGER, STRING @
DECLARE INTEGER IsIconic IN WIN32API INTEGER
DECLARE INTEGER SetForegroundWindow IN WIN32API INTEGER
DECLARE INTEGER GetWindow IN WIN32API INTEGER, INTEGER
DECLARE INTEGER ShowWindow IN WIN32API INTEGER, INTEGER
DECLARE INTEGER GetDesktopWindow IN WIN32API
DECLARE LONG FindWindow IN WIN32API LONG, STRING
#DEFINE SW_RESTORE 9
#DEFINE ERROR_ALREADY_EXISTS 183
#DEFINE GW_HWNDNEXT 2
#DEFINE GW_CHILD 5
LOCAL llRetVal, lcExeFlag, lnExeHwnd, lnHwnd
lcExeFlag = STRTRAN(_screen.caption, " ", "") + CHR(0)
lnExeHwnd = CreateMutex(0, 1, @lcExeFlag)
IF GetLastError() = ERROR_ALREADY_EXISTS
lnHwnd = GetWindow(GetDesktopWindow(), GW_CHILD)
DO WHILE lnHwnd > 0
IF GetProp(lnHwnd, @lcExeFlag) = 1
IF IsIconic(lnHwnd) > 0
ShowWindow(lnHwnd, SW_RESTORE)
ENDIF
SetForegroundWindow(lnHwnd)
EXIT
ENDIF
lnHwnd = GetWindow(lnHwnd, GW_HWNDNEXT)
ENDDO
CloseHandle(lnExeHwnd)
llRetVal = .F.
ELSE
SetProp(FindWindow(0, _screen.caption), @lcExeFlag, 1)
llRetVal = .T.
ENDIF
RETURN llRetVal
ENDFUNC
</vfp_code>
--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8
 
 
 

vfp8 - detect other copies of app running

Post by Josh Assin » Thu, 30 Oct 2003 09:31:57

Have you had any luck with ReleaseMutex()?



On Wed, 29 Oct 2003 01:01:15 +0100, "Eric den Doop"
 
 
 

vfp8 - detect other copies of app running

Post by Josh Assin » Thu, 30 Oct 2003 09:35:20

Have you had any luck with ReleaseMutex()?



On Wed, 29 Oct 2003 01:01:15 +0100, "Eric den Doop"
 
 
 

vfp8 - detect other copies of app running

Post by Jerem » Thu, 30 Oct 2003 13:48:54

Lee, thanks for the link. Looks like an elegant solution.

And thanks also to Eric for his mutex code.

Jeremy




as
rights.
 
 
 

vfp8 - detect other copies of app running

Post by Eric den D » Thu, 30 Oct 2003 17:49:15

Hello, Josh!
You wrote on Tue, 28 Oct 2003 16:31:57 -0800:

JA> Have you had any luck with ReleaseMutex()?

Never tried it.
--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8
 
 
 

vfp8 - detect other copies of app running

Post by Josh Assin » Fri, 31 Oct 2003 01:14:23

we use CreateMutex() to stop some "utility" apps to run during "critical points"
but we could never get releasemutex() to work -- and sometimes, on some OS's we
found that the app closing didn't always "clear" the mutex....


On Wed, 29 Oct 2003 09:49:15 +0100, "Eric den Doop"
 
 
 

vfp8 - detect other copies of app running

Post by nasi » Sun, 02 Nov 2003 12:45:27

Create 2 batch files.
Batch file 1. app_name.bat

@echo off
if exist app_name.don goto error

:continue
copy app_name.bat app_name.don
app_file.exe
del app_name.don
goto end

:error
echo Application Already Loaded
pause
goto end

:end

In the event the system/program is shutdown abnormally.
Batch File 2: ClearLoc.bat

@echo off
echo . Clearing Locks
if exist app_name.don del app_name.don

Nasib Kalsi




and then having
Can I prevent this?