Delphi防止程序重复运行(互斥方式)

procedure TForm1.FormCreate(Sender: TObject);

begin
    CreateMutex(nil,False,'Form1');
    if GetLastError=ERROR_ALREADY_EXISTS then
    begin
       ShowMessage('程序已运行,请勿执行多个程序实例');
      Halt(0);
    end;
end;

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注