Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

星期一, 10月 15, 2007

防止軟體程式重複被執行兩次


program Project1;

uses
ExceptionLog,
Forms,
windows,
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}
var
Mutex : THandle;

begin
Mutex := CreateMutex(nil, false, pchar(application.title));
if (Mutex = 0) OR (GetLastError = ERROR_ALREADY_EXISTS) then
begin
Application.MessageBox('不能重覆執行程式','一次只能執行一個程式',mb_ok);
// code to searh for, and activate
// the previous (first) instance
//Application.terminate;
end else begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
if Mutex <> 0 then
CloseHandle(Mutex);
end;
end.

沒有留言: