如何安装.NET Framework它尚未安装,只有当?NET、Framework

2023-09-02 21:08:14 作者:油条

有没有一种方法来检查.NET Framework 4中已安装并安装它,只有当它不是系统?

Is there a way to check if the .NET Framework 4 has been installed and install it only when it's not in the system ?

我知道,如何确定,如果.NET Framework 4的是通过检查以下注册表项安装:

I know, how to determine, if the .NET Framework 4 is installed by checking the following registry key:

hasDotnet4 := RegKeyExists(HKEY_LOCAL_MACHINE, 
  'SOFTWAREMicrosoft.NETFrameworkpolicyv4.0');

如何基于上述检查我有条件地运行在.NET Framework 4的安装?

How do I conditionally run the .NET Framework 4 installation based on the above check ?

推荐答案

你可以做最简单的,就是用 检查 的参数,它可以让你控制,如果从 [文件] 部分将被提取,或者如果从一定程序 [运行] 部分将被执行。下面的脚本code显示了它的用法的条件安装.NET Framework 4的:

The easiest you can do, is to use the Check parameter, which allows you to control if a certain file from the [Files] section will be extracted, or if a certain program from the [Run] section will be executed. The following script code shows its usage for the conditional installation of the .NET Framework 4:

[Files]
Source: "dotNetFx40_Full_setup.exe"; DestDir: {tmp}; Flags: deleteafterinstall; Check: FrameworkIsNotInstalled

[Run]
Filename: "{tmp}dotNetFx40_Full_setup.exe"; Check: FrameworkIsNotInstalled

[code]
function FrameworkIsNotInstalled: Boolean;
begin
  Result := not RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWAREMicrosoft.NETFrameworkpolicyv4.0');
end;