是否可以在尝试安装之前检查程序是否已经 运行? (创新设置)

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

我正在使用 Inno Setup 创建安装程序。当我启动我创建的安装程序时,我需要检查我要安装的程序是否已经 运行 如果它是 运行 那么我必须显示相应的消息直到我关闭它或退出。 可以吗?

如果是你的应用程序,让它创建一个互斥体。然后你可以使用 AppMutex directive.

[Setup]
AppMutex=MyProgMutex


如果您无法修改应用程序,则需要在 Inno Setup 中对 运行 应用程序的检查进行编码。例如,您可以使用 @RRUZ 对 How to check with Inno Setup, if a process is running at a Windows 2008 R2 64bit? in InitializeSetup event function.

的回答中的 IsAppRunning 函数
function InitializeSetup(): Boolean;
var
  Answer: Integer;
begin
  Result := True;
  while IsAppRunning('MyProg.exe') do
  begin
    Answer := MsgBox('Program is running, please close it', mbError, MB_OKCANCEL);
    if Answer = IDCANCEL then
    begin
      Result := False
      Exit;
    end;
  end;
end;

基于卸载程序的类似问题: