Is it possible to check if program is already running before trying to install it? (Inno Setup)

岁酱吖の 提交于 2020-03-21 03:51:44

问题


I'm using Inno Setup to create the installer. When I launch the installer I've created I need to check whether the program I'm trying to install is already running or not and if it is running then I have to show the corresponding message until I close it or exit. Is it possible to do that?


回答1:


If it is your application, make it create a mutex. Then you can use AppMutex directive.

[Setup]
AppMutex=MyProgMutex


If you cannot modify the application, you need to code the check for running application in Inno Setup. You can for example use IsAppRunning function from the answer by @RRUZ to How to check with Inno Setup, if a process is running at a Windows 2008 R2 64bit? in InitializeSetup event function.

function InitializeSetup(): Boolean;
begin
  Result := True;
  while IsAppRunning('MyProg.exe') do
  begin
    if MsgBox('Program is running, please close it', mbError, MB_OKCANCEL) = IDCANCEL then
    begin
      Result := False
      Exit;
    end;
  end;
end;

Based on a similar question on uninstaller:
Preparing to Uninstall like Preparing to Install Page - Inno Setup



来源:https://stackoverflow.com/questions/60526914/is-it-possible-to-check-if-program-is-already-running-before-trying-to-install-i

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!