您好我正在尝试在我的Inno安装脚本中集成.NET Framework版本检查和自动安装。
我正在使用我在此处找到的代码:.../installing-net-framework-4-5-automatically-with-inno-setup/`
问题是,代码无效。脚本编译并输出正常 当我尝试在VM中运行设置时,一切正常。
但是,我没有看到实际安装.NET Framework 只需一个快速的10秒进度窗口,显示正在提取的各种文件(如下所示) 然后它消失了,我的设置就完成了。
当我尝试启动程序时,它报告未安装.NET Framework。
这是完整的代码:
#include <idp.iss>
function Framework45IsNotInstalled(): Boolean;
var
bSuccess: Boolean;
regVersion: Cardinal;
begin
Result := True;
bSuccess := RegQueryDWordValue(HKLM, 'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release', regVersion);
if (True = bSuccess) and (regVersion >= 378389) then begin
Result := False;
end;
end;
procedure InitializeWizard;
begin
if Framework45IsNotInstalled() then
begin
idpAddFile('http://go.microsoft.com/fwlink/?LinkId=397707', ExpandConstant('{tmp}\NetFrameworkInstaller.exe'));
idpDownloadAfter(wpReady);
end;
end;
procedure InstallFramework;
var
StatusText: string;
ResultCode: Integer;
begin
StatusText := WizardForm.StatusLabel.Caption;
WizardForm.StatusLabel.Caption := 'Installing .NET Framework 4.5.2. This might take a few minutes…';
WizardForm.ProgressGauge.Style := npbstMarquee;
try
if not Exec(ExpandConstant('{tmp}\NetFrameworkInstaller.exe'), '/passive /norestart','', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
MsgBox('.NET installation failed with code: ' + IntToStr(ResultCode) + '.', mbError, MB_OK);
end;
finally
WizardForm.StatusLabel.Caption := StatusText;
WizardForm.ProgressGauge.Style := npbstNormal;
DeleteFile(ExpandConstant('{tmp}\NetFrameworkInstaller.exe'));
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
case CurStep of
ssPostInstall:
begin
if Framework45IsNotInstalled() then
begin
InstallFramework();
end;
end;
end;
end;
我尝试分解代码并尝试找到问题。不幸的是,我无法识别它。
任何帮助都将受到高度赞赏。谢谢!
答案 0 :(得分:1)
好吧,最后我确定了这个问题,这是一个令人尴尬的问题。我的VM没有足够的空间,但在设置脚本过程InstallFramework
中未正确报告此错误。
条件if not Exec(ExpandConstant('{tmp}\NetFrameworkInstaller.exe'), '/passive /norestart','', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
始终返回False
,即使.NET Framework安装失败也是如此。
正确的方法是只调用Exec(ExpandConstant('{tmp}\NetFrameworkInstaller.exe'), '/passive /norestart','', SW_SHOW, ewWaitUntilTerminated, ResultCode)
,然后检查实际的ResultCode
以查看.NET Framework安装是否成功。在原始脚本中,此ResultCode
的值为5100
(空间不足)。
因此,我相应地修改并修复了例程。
procedure InstallFramework;
var
StatusText: string;
ResultCode: Integer;
begin
StatusText := WizardForm.StatusLabel.Caption;
WizardForm.StatusLabel.Caption := 'Installing .NET Framework 4.5.2. This might take a few minutes...';
WizardForm.ProgressGauge.Style := npbstMarquee;
try
Exec(ExpandConstant('{tmp}\NetFrameworkInstaller.exe'), '/passive /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
if ResultCode <> 0 then
begin
MsgBox('.NET installation failed with code: ' + IntToStr(ResultCode) + '.' + #13#10 + #13#10 + 'Setup will now terminate.', mbError, MB_OK);
DeleteFile(ExpandConstant('{tmp}\NetFrameworkInstaller.exe'));
Exterminate;
end
else
begin
WizardForm.StatusLabel.Caption := StatusText;
WizardForm.ProgressGauge.Style := npbstNormal;
end;
finally
DeleteFile(ExpandConstant('{tmp}\NetFrameworkInstaller.exe'));
end;
end;
如果.NET Framework安装失败,Exterminate
过程将中止安装(没有提示)。
var
ForceClose: Boolean;
procedure Exterminate;
begin
ForceClose:= True;
WizardForm.Close;
end;
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
Confirm:= not ForceClose;
end;