检查应用程序是否正在运行
我正在使用 innosetup 为我的 Windows 应用程序创建安装。在开始安装之前,我需要检查应用程序是否已经在运行。我使用了以下代码,该代码无法正常工作。
const
WM_CLOSE = 16;
Function InitializeSetup : Boolean;
var winHwnd: longint;
retVal : boolean;
strProg: string;
begin
Result := true;
try
strProg := 'myApp.exe';
winHwnd := FindWindowByWindowName(strProg);
Log('winHwnd: ' + inttostr(winHwnd));
if winHwnd <> 0 then
retVal:=postmessage(winHwnd,WM_CLOSE,0,0);
if retVal then begin
MsgBox('Window is not running', mbInformation, MB_OK);
Result := True
end
else begin
MsgBox('Window still open', mbInformation, MB_OK);
Result := False;
end;
except
end;
end;
这里 winHwnd 始终为 0。请让我知道这段代码有什么问题。
谢谢, 曼朱
I am using innosetup to create installation for my windows application. Before starting installation i need to check whether application is already running or not. I have used the following code, which is not working properly.
const
WM_CLOSE = 16;
Function InitializeSetup : Boolean;
var winHwnd: longint;
retVal : boolean;
strProg: string;
begin
Result := true;
try
strProg := 'myApp.exe';
winHwnd := FindWindowByWindowName(strProg);
Log('winHwnd: ' + inttostr(winHwnd));
if winHwnd <> 0 then
retVal:=postmessage(winHwnd,WM_CLOSE,0,0);
if retVal then begin
MsgBox('Window is not running', mbInformation, MB_OK);
Result := True
end
else begin
MsgBox('Window still open', mbInformation, MB_OK);
Result := False;
end;
except
end;
end;
Here winHwnd is always comes as 0. Please let me know what's wrong with this code.
Thanks,
Manju
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
InnoSetup 有一个内置检查来查看您的应用程序是否正在运行,请查看
[Setup]
部分中的AppMutex
设置。您需要做的就是在应用程序中创建一个命名互斥体,并在 innosetup 脚本中指定该互斥体的名称。然后 InnoSetup 将进行检查并自行显示一条消息。InnoSetup has a built-in check to see if your application is running, look at the
AppMutex
setting in the[Setup]
section. All you need to do is create a named mutex in your application, and specify the name of that mutex in your innosetup script. InnoSetup will then do the check and display a message itself.