我在使用Inno Setup时遇到了麻烦:在用户计算机上,我的安装程序运行缓慢(我尚未诊断出的问题,可能是该计算机特有的问题,我仍然不知道)。这导致该用户在第一个实例仍在执行时再次运行安装程序-令我惊讶的是,他们似乎都运行了一段时间,然后崩溃并烧毁...
我四处搜寻,但没有找到任何禁用此行为的方法-我的大多数查询都涉及Inno Setup互斥功能,这并不是我真正想要的。任何人都获得有关如何确保安装程序仅执行一个实例/进程的提示?谢谢!
从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;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句