🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9981

Re: Implementation of run once

#9981
From: Sergiy Kanilo
Date: Thu, 27 May 2004 18:51
33 lines
1413 bytes
"Daniele Borini" <borini@infinito.it> wrote in message
news:40b5cc3f@newsgroups.borland.com...

> i need to check if my app has been already ran, to deny multiple
> executions on the same PC.

I normally add a cpp file with

#include <vcl.h>
#pragma hdrstop
#pragma package(smart_init)

class OnlyOneProgram
{
public:
  OnlyOneProgram()
  {
    handle =CreateMutex(0,true,"<special string for the application>");
    if(GetLastError()==ERROR_ALREADY_EXISTS) exit(EXIT_SUCCESS);
  }
  ~OnlyOneProgram()
  {
    ReleaseMutex(handle);
  }
private:
  HANDLE handle;
} onlyOneProgram;

to my project and edit the third argument of CreateMutex

Cheers,
Serge
Technical Details
Message-ID: <2hmrmlFes454U1@uni-berlin.de>
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail
References: <40b5cc3f@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,91ebf45a6fbd8e57
X-Google-Attributes: gid10cc67,public
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail
From: "Sergiy Kanilo" <skanilo@artannlabs.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Implementation of run once
Date: Thu, 27 May 2004 14:51:57 -0400
Lines: 35
Message-ID: <2hmrmlFes454U1@uni-berlin.de>
References: <40b5cc3f@newsgroups.borland.com>
X-Trace: news.uni-berlin.de YKN0wzFOp9h3s0iWBBmxZgPl5DC7KcSbX95fPWK/SKEIiIEj1E
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409