Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
If a particular Fox exe is running, don't start it again
Message
 
À
23/06/2005 23:20:01
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01026146
Message ID:
01026149
Vues:
17
>How would I code:
>
>If myprog.exe is running
> Don't run it again
>Endif

Here is what I use for it:
* At the beginning of your Main Prg
IF IsRunning(SomeUniqueForApplicationString)
   MessageBox("Application is already running")
   QUIT
ENDIF



FUNCTION IsRunning(tcSemaphoreName)
    LOCAL lpszSemName
    #Define ERROR_ALREADY_EXISTS 183
    Declare Integer GetLastError In win32API
    Declare Integer CreateSemaphore In WIN32API ;
            string @ lpSemaphoreAttributes, ;
            LONG lInitialCount, ;
            LONG lMaximumCount, ;
            string @ lpName

    app_href = CreateSemaphore(0,0,1,tcSemaphoreName)
RETURN (app_href # 0 .AND. GetLastError() == ERROR_ALREADY_EXISTS)
The original code of that function is made by Cetin (I think), at least I get it from his post here.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform