Fórum Como Impedir Um Executável Ser Instânciado Mais de Uma Vez ? #179577
03/09/2003
0
Como Impedir Um Executável Ser Instânciado Mais de Uma Vez ?
Caso alguém saiba, me ajudaria muito!
Grato.
Alex. :)
Caso alguém saiba, me ajudaria muito!
Grato.
Alex. :)
Alex_
Curtir tópico
+ 0
Responder
Posts
03/09/2003
Cebikyn
Você pode usar uma das duas opções abaixo:
Opção 1:
Opção 2:
Opção 1:
unit Unit1;
uses
Windows, Dialogs, Sysutils;
{....}
implementation
{....}
var
mHandle: THandle;
initialization
mHandle := CreateMutex(nil, True, ´XYZ´);
if GetLastError = ERROR_ALREADY_EXISTS then
begin
ShowMessage(´Já há uma instância deste programa.´);
halt;
end;
finalization
if mHandle <> 0 then CloseHandle(mHandle)
end.Opção 2:
procedure TForm1.FormCreate(Sender: TObject); var Sem: THandle; begin Sem := CreateSemaphore(nil, 0, 1, ´NOME_DO_PROGRAMA´); if ((Sem <> 0) and (GetLastError = ERROR_ALREADY_EXISTS)) then begin CloseHandle(Sem); ShowMessage(´Já há uma instância deste programa.´); Halt; end; end;
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)