简体   繁体   English

InnoSetup:用于在文件/文件夹存在时取消设置的Pascal脚本

[英]InnoSetup: Pascal script for cancelling setup when file/folder exists

In my InnoSetup I use several file actions in the InstallRun section. 在我的InnoSetup中,我在InstallRun部分中使用了几个文件操作。 If those are executed correctly without problems then a certain temp folder should have been deleted. 如果这些执行正确没有问题,那么应该删除某个临时文件夹。

If something has gone wrong then the temp folder is still there. 如果出现问题,那么临时文件夹仍然存在。 In that case I want the setup to be canceled with a messagebox displaying an error message of my choice. 在这种情况下,我希望使用显示我选择的错误消息的消息框取消设置。

As I have no experience (yet) with Pascal script I kindly ask you to provide me with an example script yo do this. 由于我还没有使用Pascal脚本的经验,所以请您提供一个示例脚本来执行此操作。

Thanks in advance! 提前致谢!

Addition: I'll now explain the reason I need this. 另外:我现在解释一下我需要这个的原因。 The scenario is updating an existing version, which is a Windows Service application. 该方案是更新现有版本,即Windows Service应用程序。 Before updating those files I have to uninstall the services first. 在更新这些文件之前,我必须先卸载服务。 For this I use my own commandline that's in the installation package. 为此,我使用自己的命令行在安装包中。 The other new files will be temporary unpacked to a temp folder (subfolder of app folder). 其他新文件将临时解压缩到临时文件夹(app文件夹的子文件夹)。 After the Windows services are uninstalled the new files are moved from the temp folder to the app folder. 卸载Windows服务后,新文件将从临时文件夹移动到app文件夹。 If something goes wrong here I want to cancel the setup and show an error message to the user. 如果出现问题,我想取消设置并向用户显示错误消息。 I can best tell if something has gone wrong by checking if the temp folder is still there. 通过检查temp文件夹是否仍然存在,我可以最好地判断是否出现了问题。

Assuming that you mean the [Run] section, it is not possible to cancel the installation that late in the process. 假设您的意思是[Run]部分,则无法取消该过程后期的安装。

Instead, you should look at using PrepareToInstall . 相反,您应该考虑使用PrepareToInstall In this, all you need to do is to stop and deregister the old service, either directly via API or by invoking a command on the old service EXE as you choose. 在这里,您需要做的就是直接通过API或在您选择的旧服务EXE上调用命令来停止和取消注册旧服务。 (Don't forget to handle the case when the service doesn't exist yet, for new installs.) (对于新安装,不要忘记在服务尚不存在的情况下处理。)

After this [Files] will replace the files as normal and you can then [Run] or use code (via AfterInstall or CurStepChanged(ssPostInstall) , depending on the time you want it to happen) to re-register and start the service. 在此[Files]将正常替换文件后,您可以[Run]或使用代码(通过AfterInstallCurStepChanged(ssPostInstall) ,取决于您希望它发生的时间)重新注册和启动服务。

No need to muck around with temporary folders -- which is good, because that would have caused problems for uninstall as well. 不需要使用临时文件夹 - 这很好,因为这也会导致卸载问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM