防止同一实例多个运行

procedure Tloginform.FormCreate(Sender: TObject);
var
    errno:integer;
    hmutex:hwnd;
begin
    hmutex:=createmutex(nil,false,pchar(application.Title));
    errno:=getlasterror;
    if errno=error_already_exists then
    begin
        application.MessageBox(' 您已经打开了该软件'+#13#13+' 请   不要再尝试'+#13#13+'您只能运行一个程序实例','不要试图打开多个',mb_ok);
        application.Terminate;
    end;
end;
posted on 2012-11-30 15:56  天 火  阅读(245)  评论(0编辑  收藏  举报