检查应用程序是否正在运行

发布于 2024-09-17 16:59:34 字数 775 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫性小仙女 2024-09-24 16:59:34

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文