让程序只运行一个实例

var
  hMutex: HWND;

begin
  //hMutex := CreateMutex(nil,True,'_MingTest');
  hMutex := CreateEvent(nil,False,False,'_MingTest');
  if GetLastError = ERROR_ALREADY_EXISTS then
  begin
    MessageBox(0,'This program has executed!','Error!',0);
    Exit;
  end;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
原文地址:https://www.cnblogs.com/Jekhn/p/2126992.html