Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A New Twist On Is App Running
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00409058
Message ID:
00409480
Views:
26
I tried the other methods and did not like the way they worked.
Here is a method that works for me.

**************************************************
*** This code is in the CheckTempDirs.Init method.
**************************************************
LPARAMETERS tcAppName
LOCAL lcSaveError, lcFileName, lcAppName, llResourceInUse

*** VFP does not like spaces in directory names
lcAppName = STRTRAN(tcAppName, " ", "")
oMiscFunctions = CREATEOBJECT("MiscFunctions")

WAIT WINDOW NOWAIT "Checking for required Directories"

*** Check for the VisualFoxPro directory
lcFileName = "C:\VisualFoxPro"
IF ! oMiscFunctions.IsDir(lcFileName)
MKDIR &lcFileName
ENDIF

*** Check for the Temp files directory
lcFileName = "C:\VisualFoxPro\Temp"
IF ! oMiscFunctions.IsDir(lcFileName)
MKDIR &lcFileName
ENDIF

*** Check for the application directory
lcFileName = "C:\VisualFoxPro\" + lcAppName
IF ! oMiscFunctions.IsDir(lcFileName)
MKDIR &lcFileName
ENDIF

RELEASE oMiscFunctions

*** Make sure the application's FoxUser database exists.
lcFileName = "C:\VisualFoxPro\" + lcAppName + "\foxuser.dbf"
IF ! FILE(lcFileName)
CREATE TABLE (lcFileName) ;
(Type C(12), Id C(12), Name M, ReadOnly L, CkVal N(6,0), Data M, Updated D)
USE IN FoxUser
ENDIF

*** Save Error routine and set a do nothing command,
*** So that Delete File does not display an error if a file can not be deleted.
lcSaveError = ON("ERROR")

ON ERROR WAIT WINDOW NOWAIT "Deleting temp files"

*** Delete temp files
WAIT WINDOW NOWAIT "Deleting temp files"
DELETE FILE C:\VisualFoxPro\Temp\*.dbf
DELETE FILE C:\VisualFoxPro\Temp\*.fpt
DELETE FILE C:\VisualFoxPro\Temp\*.txt
DELETE FILE C:\VisualFoxPro\Temp\*.tmp

*** Turn on FoxUser database
*** if it is in use, then TaskTrak is already running
*** THIS.llResourceInUse can not be used in ON ERROR
llResourceInUse = .F.
ON ERROR llResourceInUse = .T.

SET RESOURCE TO &lcFileName
SET RESOURCE ON

THIS.llResourceInUse = llResourceInUse

*** Restore error routine
ON ERROR &lcSaveError

WAIT CLEAR
RETURN


**************************************************
*** The following code is in my startup program.
**************************************************

WAIT WINDOW NOWAIT "Checking for temp directories..."

*** Make sure the FoxPro temp dir exists
oCheckTemp = CREATEOBJECT("CheckTempDir", app_title)
*** CheckTempDir also checks to see if the Foxuser.dbf is in use
*** If it is then the app is already running.
IF oCheckTemp.llResourceInUse
MessageBox("Use Alt+Tab to bring TaskTrak 2000 to the top.", ;
48, "TaskTrak 2000 is Already Running")
QUIT
ENDIF
RELEASE oCheckTemp
Dennis Lindeman
Previous
Reply
Map
View

Click here to load this message in the networking platform