將以下代碼加到 工程文件中 即 .dpr 文件中
const iAtom='you exe name'; //如jzl
VAR
Mutex:THandle;
begin
Mutex:=CreateMutex(NIL,True,'you exe name');
IF GetLastError <> ERROR_ALREADY_EXISTS THEN
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end
else
MessageBox(0,'已經有一個程序在本機運行!','提示',mb_OK+MB_ICONINFORMATION);
ReleaseMutex(Mutex);