I supposed, that the program name is "Test", then next code will not allow to execute second instance of the program "Test".
//----------------------------------------------------------static int runing = 0;
//----------------------------------------------------------bool __stdcall EnumProc(HWND hWnd,long)
{
unsigned long* pPid;
unsigned long result;
void *hg;
unsigned long id;
if(hWnd==NULL)
return false;
hg = GlobalAlloc(GMEM_SHARE,sizeof(unsigned long));
pPid = (unsigned long *)GlobalLock(hg);
result = GetWindowThreadProcessId(hWnd,pPid);
if(result)
{
char className[95];
char title[256];
GetClassName(hWnd,className,95);
GetWindowText(hWnd,title,110);
if(!strcmp(className,"TApplication"

&&
!strcmp(title,"Test"

)
runing++;
}
GlobalUnlock(hg);
GlobalFree(hg);
return true;
}
//----------------------------------------------------------void __fastcall TFormTest::FormActivate(TObject *Sender)
{
EnumChildWindows(GetDesktopWindow(),(WNDENUMPROC) EnumProc,0);
if(runing == 2)
{
MessageBox(0,"Already runing!","Waring!",MB_OK);
Close();
}
}
//----------------------------------------------------------