Delphi   发布时间:2022-04-10  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了inno-setup – Inno Setup – 防止同时多次执行安装程序大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我对Inno安装程序有点厌倦:在用户计算机上,我的安装程序运行缓慢(我尚未诊断的东西,可能是该计算机特有的问题,我仍然不知道).这导致所述用户再次运行安装程序,而第一个实例仍在执行 – 令我惊讶的是,他们似乎都在运行一段时间,然后崩溃并烧毁…… @H_197_2@我四处搜索但没有找到任何方法来禁用此行为 – 我的大部分疑问都在Inno Setup互斥功能上完成,这不是我想要的.任何人都有关于如何确保安装程序只有一个实例/进程执行的提示?谢谢!

@H_618_4@

解决方法

自Inno Setup 5.5.6起,您可以使用 SetupMutex指令:
[Setup]
AppId=MyProgram
SetupMutex=SetupMutex{#SetupSetTing("AppId")}
@H_197_2@如果要更改已在另一个安装程序运行时显示的消息文本,请使用:

[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.
@H_197_2@在此版本之前,没有可用的内置机制.但你可以简单地写自己的.原则是您在安装程序启动时创建一个唯一的互斥锁.但是,首先检查是否已经创建了这样的互斥锁.如果是,则退出设置,否则,创建互斥锁:

[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 https://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;
@H_618_4@ @H_618_4@

大佬总结

以上是大佬教程为你收集整理的inno-setup – Inno Setup – 防止同时多次执行安装程序全部内容,希望文章能够帮你解决inno-setup – Inno Setup – 防止同时多次执行安装程序所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。