delphi 判断程序是否已经运行  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi 判断程序是否已经运行


1。在工程单元中引用windows单元。

2。定义一个变量,类型为hMutex:THandle.

3. hMutex := CreateMutex(nil, False, 'TheStandard');

4.if GetLastError = ERROR_ALREADY_EXISTS then
begin

   CloseHandle(hMutex);
    ShowMessage('本软件的另一个副本已经在运行中');
    application.Terminate;
end
else
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end;

例如:

program Project1;

uses
Forms,Windows,Dialogs,
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}
var
hMutex: THandle;
begin
Application.Initialize;
hMutex := CreateMutex(nil, False, 'TheStandard');
if GetLastError = ERROR_ALREADY_EXISTS then
begin

    CloseHandle(hMutex);
    ShowMessage('本软件的另一个副本已经在运行中');
    application.Terminate;
end
else
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end;
end.

例如:


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.06395411491394 seconds