Inno Setup:验证是否已安装 .NET 4.0
我有一个需要 .NET 4.0 才能运行的组件,我的 Inno Setup 安装程序如何验证它是否已安装,如果没有,则提示用户安装它?
I have a component that requires .NET 4.0 to run, how can my Inno Setup installer verify that it is installed, and if not, prompt the user to install it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Inno Setup 可执行文件运行时会调用
InitializeSetup
函数。为自定义脚本插入此代码应该可以执行您想要的操作:(代码取自此处:http://www. kynosarges.de/DotNetVersion.html)
首先,它检查是否存在指示所安装的 .NET 框架版本的注册表项。如果注册表项不存在,则会提示用户下载 .NET Framework。如果用户选择“是”,则会打开下载 URL。 (您可能需要将脚本中指定的版本更改为版本 4.0。)
I also came across [this article on CodeProject][1], which may be a more comprehensive and customizable way of doing what you're looking for, although it may take more work to understand and will have to be modified to work with version 4.0.
The
InitializeSetup
function is called when the Inno Setup executable is run. Inserting this code for a custom script should do what you want:(Code taken from here: http://www.kynosarges.de/DotNetVersion.html)
First, it checks for the presence of a registry entry that indicates the version of the .NET framework that is installed. If the registry entry is not present, it prompts the user to download the .NET framework. If the user says Yes, it opens the download URL. (You may have to change the version it specifies in the script to version 4.0.)
I also came across [this article on CodeProject][1], which may be a more comprehensive and customizable way of doing what you're looking for, although it may take more work to understand and will have to be modified to work with version 4.0.
@Cody Gray - 感谢您的解决方案。非常有帮助!
如果有人感兴趣,这是我对他的函数的看法,使用枚举值而不是字符串。这种变化纯粹是个人喜好问题。该代码包含 v4.5 的更改,根据我有限的测试,似乎可以正常工作。
大卫
@Cody Gray - Thanks for your solution. Very helpful!
In case anyone is interested, here is my take on his function using enumeration values instead of strings. This change is purely a matter of personal preference. The code includes the changes for v4.5 and seems to work properly based on my limited testing.
David
我发现这个功能至少从 innosetup 6.0.5 版本开始就已经成为框架的一部分。因此,您不必自己编写该函数的代码。
函数:
IsDotNetInstalled
这是一个简短的示例:
I found out that this functionality has been part of the framework since at least innosetup version 6.0.5. Therefore, you do not necessarily have to code the function yourself.
Function:
IsDotNetInstalled
Here is a short example:
如果您不关心是否安装了 .NET 4 的“完整”版本或仅安装了“客户端”版本:
If you don't care if the "Full" or just the "Client" version of .NET 4 is installed:
感谢大家提供的现有解决方案,它们效果很好。
不过,我不需要支持每个框架版本,但一次只需支持一个,并且不需要“古老”的版本(.NET 4.0 或更早版本)。我也不需要检查服务版本。
因此,代码变得简单很多,而且我发现减少噪音更好:
您只需将上面的代码中的版本常量 (
461808
) 替换为您想要的值需要从 Microsoft 参考页面并相应地更新错误消息。Thanks to everyone for the existing solutions, they work great.
Still, I didn't need to support every framework version, but only one at a time, and no "ancient" ones (.NET 4.0 or older). I don't need to check for service releases too.
So, the code gets a lot simpler, and I find the reduced noise preferrable:
You just need to replace in the code above the version constant (
461808
) with the value you need from the Microsoft reference page and update the error message accordingly.