请各位多多帮忙,我想一台机器上只可以运行一个应用程序,相同的第二个不允许。不知道该如何做,请各位多多帮忙!!!!

解决方案 »

  1.   

    修改工程文件如下:
    program Project1;uses
      Forms,
      Windows,
      Unit1 in 'Unit1.pas' {Form1};{$R *.res}
    var
        hMutex:hWnd;
    begin
      Application.Initialize;
      Application.Title:='test';
      hMutex:=CreateMutex(nil,false,'test');
      if GetLastError<>Error_Already_Exists then
      begin
        Application.CreateForm(TForm1, Form1);
        Application.Run;
      end
      else
      begin
        Application.MessageBox('本程序只允许同时运行一个','Error');
        ReleaseMutex(hMutex);
      end;
    end.