inno-setup - Inno Setup - 防止同时多次执行安装程序

标签 inno-setup

我对 Inno Setup 有点不满:在用户机器上,我的安装程序运行缓慢(我还没有诊断出一些问题,可能是那台计算机的特定问题,我仍然不知道)。这导致所述用户再次运行安装程序,而第一个实例仍在执行 - 令我惊讶的是,它们似乎都运行了一段时间,然后崩溃和燃烧......

我四处搜索,但没有找到任何方法来禁用此行为 - 我的大多数查询都涉及 Inno Setup mutex 功能,这并不是我真正想要的。有人知道如何确保安装程序只执行一个实例/进程的提示吗?谢谢!

最佳答案

从 Inno Setup 5.5.6 开始,您可以使用 SetupMutex 指示:

[Setup]
AppId=MyProgram
SetupMutex=SetupMutex{#SetupSetting("AppId")}

如果要更改已在另一个安装程序运行时显示的消息文本,请使用:
[Messages]
SetupAppRunningError=Setup has detected that %1 is currently running.%n%nPlease close all instances of it now, then click OK to continue, or Cancel to exit.

在此版本之前,没有可用的内置机制。但是你可以很简单地编写你自己的。原则是在设置开始时创建一个唯一的互斥锁。但是,首先您要检查是否已经创建了这样的互斥锁。如果是,则退出设置,如果不是,则创建互斥锁:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
const
  { this needs to be system-wide unique name of the mutex (up to MAX_PATH long), }
  { there is a discussion on this topic http://stackoverflow.com/q/464253/960757 }
  { you can expand here e.g. the AppId directive and add it some 'salt' }
  MySetupMutex = 'My Program Setup 2336BF63-DF20-445F-AAE6-70FD7E2CE1CF';

function InitializeSetup: Boolean;
begin
  { allow the setup to run only if there is no thread owning our mutex (in other }
  { words it means, there's no other instance of this process running), so allow }
  { the setup if there is no such mutex (there is no other instance) }
  Result := not CheckForMutexes(MySetupMutex);
  { if this is the only instance of the setup, create our mutex }
  if Result then
    CreateMutex(MySetupMutex)
  { otherwise tell the user the setup will exit }
  else
    MsgBox('Another instance is running. Setup will exit.', mbError, MB_OK);
end;

关于inno-setup - Inno Setup - 防止同时多次执行安装程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28628699/

相关文章:

inno-setup - 如何在 InnoSetup 中更改 {app} 变量

inno-setup - TNewCheckListBox 选中未更新

inno-setup - Inno Setup,根据脚本函数的结果提示任务

c - 在 Inno Setup 中使用回调显示来自外部解压 dll 的文件名

registry - 从 Windows 注册表获取 Office 应用程序的版本和平台

inno-setup - 如何使Inno Setup显示MsgBox并在指定时间后自动关闭它

java - Inno 安装程序 : Removing files installed by previous version

inno-setup - 更改 Inno Setup 中 WizardForm 页面上的标签文本

inno-setup - 隐藏Inno Setup进度页面中的文件名

installation - InnoSetup:在[代码]部分中获取AppName