将你的项目文件这样设置就OK了哦!
program 应用程序;
uses
Forms,
{$R *.RES}
var
MutexHandle: THandle;
//定义互斥句柄
//防止二次运行
begin
//whether existed
MutexHandle := CreateMutex(nil, TRUE, 'XXXX管理系统');
if MutexHandle <> 0 then
begin
if GetLastError = ERROR_ALREADY_EXISTS then
begin
MessageBox(0, '程序已经运行...',
'警告', mb_IconHand);
CloseHandle(MutexHandle);
Halt;
// 'Halt' Is stop running the actual application.
end;
end;
Application.Initialize;
{
.......
}
Application.Run;
end.