Option not to start several instances
Status: Beta
Brought to you by:
noja
In my experience it can be useful if applications doesn't allow
several instances running. This is especially true on my system
when "tray'ed" applications are involved since an explorer
restart will flush most of the icons in the tray. Starting the
application will then give the user control of the old instance.
Of course this should be an option for the user to decide.
Logged In: YES
user_id=553457
Here's the code for that:
MainFormUnit:
var
mHandle: THandle; { dragod 020527 }
procedure TMainForm.FormCreate(Sender: TObject);
var { dra.:.god 020527 }
Sem: THandle; { dra.:.god 020527 }
begin
{ dragod 020527 begin }
Sem := CreateSemaphore(nil, 0, 1, 'edk_ServSpy');
if ((Sem <> 0) and (GetLastError =
ERROR_ALREADY_EXISTS)) then
begin
CloseHandle(Sem);
ShowMessage('ServerSpy is already running.');
Halt;
end;
{ dragod 020527 end }
and at the end of the file befor end.
{ dragod 020527 start }
initialization
mHandle := CreateMutex(nil, True, 'XYZ');
if GetLastError = ERROR_ALREADY_EXISTS then
begin
ShowMessage('ServerSpy is already running.');
halt;
end;
finalization
if mHandle <> 0 then CloseHandle(mHandle)
{ dragod 020527 end }
ive tested it and it work... servspy starts only one time...
dra.:.god