[Code] functionIsDotNetDetected(version: string; service: cardinal): boolean; // Indicates whether the specified version and service pack of the .NET Framework is installed. // // version -- Specify one of these strings for the required .NET Framework version: // 'v1.1' .NET Framework 1.1 // 'v2.0' .NET Framework 2.0 // 'v3.0' .NET Framework 3.0 // 'v3.5' .NET Framework 3.5 // 'v4\Client' .NET Framework 4.0 Client Profile // 'v4\Full' .NET Framework 4.0 Full Installation // 'v4.5' .NET Framework 4.5 // 'v4.5.1' .NET Framework 4.5.1 // 'v4.5.2' .NET Framework 4.5.2 // 'v4.6' .NET Framework 4.6 // 'v4.6.1' .NET Framework 4.6.1 // 'v4.6.2' .NET Framework 4.6.2 // 'v4.7' .NET Framework 4.7 // 'v4.7.1' .NET Framework 4.7.1 // 'v4.7.2' .NET Framework 4.7.2 // 'v4.8' .NET Framework 4.8 // // service -- Specify any non-negative integer for the required service pack level: // 0 No service packs required // 1, 2, etc. Service pack 1, 2, etc. required var key, versionKey: string; install, release, serviceCount, versionRelease: cardinal; success: boolean; begin versionKey := version; versionRelease := 0;
// .NET 1.1 and 2.0 embed release number in version key if version = 'v1.1'thenbegin versionKey := 'v1.1.4322'; endelseif version = 'v2.0'thenbegin versionKey := 'v2.0.50727'; end
// .NET 4.5 and newer install as update to .NET 4.0 Full elseif Pos('v4.', version) = 1thenbegin versionKey := 'v4\Full'; case version of 'v4.5': versionRelease := 378389; 'v4.5.1': versionRelease := 378675; // 378758 on Windows 8 and older 'v4.5.2': versionRelease := 379893; 'v4.6': versionRelease := 393295; // 393297 on Windows 8.1 and older 'v4.6.1': versionRelease := 394254; // 394271 before Win10 November Update 'v4.6.2': versionRelease := 394802; // 394806 before Win10 Anniversary Update 'v4.7': versionRelease := 460798; // 460805 before Win10 Creators Update 'v4.7.1': versionRelease := 461308; // 461310 before Win10 Fall Creators Update 'v4.7.2': versionRelease := 461808; // 461814 before Win10 April 2018 Update 'v4.8': versionRelease := 528040; // 528049 before Win10 May 2019 Update end; end;
// installation key group for all .NET versions key := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\' + versionKey;
// .NET 3.0 uses value InstallSuccess in subkey Setup if Pos('v3.0', version) = 1thenbegin success := RegQueryDWordValue(HKLM, key + '\Setup', 'InstallSuccess', install); endelsebegin success := RegQueryDWordValue(HKLM, key, 'Install', install); end;
// .NET 4.0 and newer use value Servicing instead of SP if Pos('v4', version) = 1thenbegin success := success and RegQueryDWordValue(HKLM, key, 'Servicing', serviceCount); endelsebegin success := success and RegQueryDWordValue(HKLM, key, 'SP', serviceCount); end;
// .NET 4.5 and newer use additional value Release if versionRelease > 0thenbegin success := success and RegQueryDWordValue(HKLM, key, 'Release', release); success := success and (release >= versionRelease); end;
result := success and (install = 1) and (serviceCount >= service); end;
functionInitializeSetup(): Boolean; begin ifnot IsDotNetDetected('v4.6', 0) thenbegin MsgBox('MyApp requires Microsoft .NET Framework 4.6.'#13#13 'Please use Windows Update to install this version,'#13 'and then re-run the MyApp setup program.', mbInformation, MB_OK); result := false; endelse result := true; end;
[Code] functionIsDotNetDetected(version: string; service: cardinal): boolean; // Indicates whether the specified version and service pack of the .NET Framework is installed. // see the link: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed?redirectedfrom=MSDN#net_b // // version -- Specify one of these strings for the required .NET Framework version: // 'v1.1.4322' .NET Framework 1.1 // 'v2.0.50727' .NET Framework 2.0 // 'v3.0' .NET Framework 3.0 // 'v3.5' .NET Framework 3.5 // 'v4\Client' .NET Framework 4.0 Client Profile // 'v4\Full' .NET Framework 4.0 Full Installation // 'v4.5' .NET Framework 4.5 378389 // 'v4.6' .NET Framework 4.6 393295 // 'v4.6.1' .NET Framework 4.6.1 394254 // 'v4.6.2' .NET Framework 4.6.2 394802 // 'v4.7' .NET Framework 4.7 393295 // // service -- Specify any non-negative integer for the required service pack level: // 0 No service packs required // 1, 2, etc. Service pack 1, 2, etc. required var key: string; install, release, serviceCount: cardinal; check45, success: boolean; var reqNetVer : string; begin // .NET 4.5 installs as update to .NET 4.0 Full if version = 'v4.5'thenbegin version := 'v4\Full'; check45 := true; endelse check45 := false;
// installation key group for all .NET versions key := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\' + version;
// .NET 3.0 uses value InstallSuccess in subkey Setup if Pos('v3.0', version) = 1thenbegin success := RegQueryDWordValue(HKLM, key + '\Setup', 'InstallSuccess', install); endelsebegin success := RegQueryDWordValue(HKLM, key, 'Install', install); end;
// .NET 4.0/4.5 uses value Servicing instead of SP if Pos('v4', version) = 1thenbegin success := success and RegQueryDWordValue(HKLM, key, 'Servicing', serviceCount); endelsebegin success := success and RegQueryDWordValue(HKLM, key, 'SP', serviceCount); end;
// .NET 4.5 uses additional value Release if check45 thenbegin success := success and RegQueryDWordValue(HKLM, key, 'Release', release); success := success and (release >= 378389); end;
result := success and (install = 1) and (serviceCount >= service); end;
function IsRequiredDotNetDetected(): Boolean; begin result := IsDotNetDetected('v4\Full', 0); end;
如果需要,我们还可以在设置过程中发布一条消息:
1 2 3 4 5 6 7 8 9
functionInitializeSetup(): Boolean; begin ifnot IsDotNetDetected('v4\Full', 0) thenbegin MsgBox('{#MyAppName} requires Microsoft .NET Framework 4.0 Client Profile.'#13#13 'The installer will attempt to install it', mbInformation, MB_OK); end
result := true; end;
代码部分已经完成,现在我们可以关注**[Files]**部分。
1 2
[Files] Source: "{#MyDistFolder}\dotNetFx40_Full_setup.exe"; DestDir: {tmp}; Flags: deleteafterinstall; Check: not IsRequiredDotNetDetected
[Code] procedureInstallFramework; var ResultCode: Integer; begin ifnot Exec(ExpandConstant('{tmp}\dotNetFx40_Full_x86_x64.exe'), '/q /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin { you can interact with the user that the installation failed } MsgBox('.NET installation failed with code: ' + IntToStr(ResultCode) + '.', mbError, MB_OK); end; end;
An exception will be raised if an attempt is made to expand this constant on a system with no .NET Framework version 1.1 present.
32位.NET Framework 1.1版根目录。
会将系统扩展到当前的.NET Framework版本1.1会发生例外。
{dotnet20}
.NET Framework version 2.0-3.5 root directory. {dotnet20} is equivalent to {dotnet2032} unless the install is running in [64-bit install mode], in which case it is equivalent to {dotnet2064}.
An exception will be raised if an attempt is made to expand this constant on a system with no .NET Framework version 2.0-3.5 present.
32-bit .NET Framework version 2.0-3.5 root directory.
An exception will be raised if an attempt is made to expand this constant on a system with no .NET Framework version 2.0-3.5 present.
32位.NET Framework 2.0-3.5版根目录。
会将系统扩展到当前的.NET Framework版本2.0-3.5将会发生例外。
{dotnet2064}
64-bit Windows only: 64-bit .NET Framework version 2.0-3.5 root directory.
An exception will be raised if an attempt is made to expand this constant on a system with no .NET Framework version 2.0-3.5 present.
仅适用于64位Windows:64位.NET Framework 2.0-3.5版根目录。
会将系统扩展到当前的.NET Framework版本2.0-3.5将会发生例外。
{dotnet40}
.NET Framework version 4.0 and later root directory. {dotnet40} is equivalent to {dotnet4032} unless the install is running in [64-bit install mode], in which case it is equivalent to {dotnet4064}.
An exception will be raised if an attempt is made to expand this constant on a system with no .NET Framework version 4.0 or later present.
// Other parts of installer file go here [CustomMessages] IDP_DownloadFailed=Download of .NET Framework 4.7.2 failed. .NET Framework 4.7is required to run VidCoder. IDP_RetryCancel=Click 'Retry'totry downloading the files again, or click 'Cancel'to terminate setup. InstallingDotNetFramework=Installing .NET Framework 4.7.2. This might take a few minutes... DotNetFrameworkFailedToLaunch=Failed to launch .NET Framework Installer with error "%1". Please fix the error then run this installer again. DotNetFrameworkFailed1602=.NET Framework installation was cancelled. This installation can continue, but be aware that this application may not run unless the .NET Framework installation is completed successfully. DotNetFrameworkFailed1603=A fatal error occurred while installing the .NET Framework. Please fix the error, then run the installer again. DotNetFrameworkFailed5100=Your computer does not meet the requirements of the .NET Framework. Please consult the documentation. DotNetFrameworkFailedOther=The .NET Framework installer exited with an unexpected status code "%1". Please review any other messages shown by the installer to determine whether the installation completed successfully, and abort this installation and fix the problem if it did not.
[Code]
var requiresRestart: boolean;
functionNetFrameworkIsMissing(): 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 >= 461308) thenbegin Result := False; end; end;
procedureInitializeWizard; begin if NetFrameworkIsMissing() then begin idpAddFile('http://go.microsoft.com/fwlink/?LinkId=863262', ExpandConstant('{tmp}\NetFrameworkInstaller.exe')); idpDownloadAfter(wpReady); end; end;
functionInstallFramework():String; var StatusText: string; ResultCode: Integer; begin StatusText := WizardForm.StatusLabel.Caption; WizardForm.StatusLabel.Caption := CustomMessage('InstallingDotNetFramework'); WizardForm.ProgressGauge.Style := npbstMarquee; try ifnot Exec(ExpandConstant('{tmp}\NetFrameworkInstaller.exe'), '/passive /norestart /showrmui /showfinalerror', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin Result := FmtMessage(CustomMessage('DotNetFrameworkFailedToLaunch'), [SysErrorMessage(resultCode)]); end else begin // See https://msdn.microsoft.com/en-us/library/ee942965(v=vs.110).aspx#return_codes case resultCode of 0: begin // Successful end; 1602 : begin MsgBox(CustomMessage('DotNetFrameworkFailed1602'), mbInformation, MB_OK); end; 1603: begin Result := CustomMessage('DotNetFrameworkFailed1603'); end; 1641: begin requiresRestart := True; end; 3010: begin requiresRestart := True; end; 5100: begin Result := CustomMessage('DotNetFrameworkFailed5100'); end; elsebegin MsgBox(FmtMessage(CustomMessage('DotNetFrameworkFailedOther'), [IntToStr(resultCode)]), mbError, MB_OK); end; end; end; finally WizardForm.StatusLabel.Caption := StatusText; WizardForm.ProgressGauge.Style := npbstNormal;
functionPrepareToInstall(var NeedsRestart: Boolean):String; begin // 'NeedsRestart' only has an effect if we return a non-empty string, thus aborting the installation. // If the installers indicate that they want a restart, this should be done at the end of installation. // Therefore we set the global 'restartRequired' if a restart is needed, and return this from NeedRestart()
if NetFrameworkIsMissing() then begin Result := InstallFramework(); end; end;
functionNeedRestart(): Boolean; begin Result := requiresRestart; end;
functionInstallFrameworkWebRuntime():String; var WasVisible: Boolean; ResultCode: Integer; begin ExtractTemporaryFile('{#DotNetFrameWorkWebInstaller}'); WasVisible := WizardForm.PreparingLabel.Visible; try WizardForm.PreparingLabel.Visible := True; WizardForm.PreparingLabel.Caption := FmtMessage(CustomMessage('DotNetFrameworkWebInstallerCaption'), [TO_COMPARE_DOT_NET]); ExtractTemporaryFile('{#DotNetFrameWorkWebInstaller}'); //if not Exec(ExpandConstant('{tmp}\{#DotNetFrameWorkWebInstaller}'), '/q /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then ifnot Exec(ExpandConstant('{tmp}\{#DotNetFrameWorkWebInstaller}'), '/passive /norestart /showrmui /showfinalerror', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin // https://docs.microsoft.com/de-de/windows/win32/debug/system-error-codes--0-499- // you can interact with the user that the installation failed, for example: error code 2: the system cannot find the file specified. Result := FmtMessage(CustomMessage('DotNetFrameworkFailedToLaunch'), [SysErrorMessage(ResultCode)]) end else begin case ResultCode of 0: begin // Successful end; 1602 : begin MsgBox(CustomMessage('DotNetFrameworkFailed1602'), mbInformation, MB_OK); end; 1603: begin Result := CustomMessage('DotNetFrameworkFailed1603'); end; 1641: begin bRequiresRestart := True; end; 3010: begin bRequiresRestart := True; end; 5100: begin Result := CustomMessage('DotNetFrameworkFailed5100'); end; elsebegin //MsgBox(FmtMessage(CustomMessage('DotNetFrameworkFailedOther'), [IntToStr(resultCode)]), mbError, MB_OK); Result := FmtMessage(CustomMessage('DotNetFrameworkFailedOther'), IntToStr(ResultCode)); end; end; end; finally WizardForm.PreparingLabel.Visible := WasVisible; end; DeleteFile(ExpandConstant('{tmp}{#DotNetFrameWorkWebInstaller}')); end;
EXE files such as RegAsm.exe are categorized as Executable Application (Windows Executable) files. As a Windows Executable file, it was created for use in Windows 10 by [Microsoft].
The first version of RegAsm.exe for Windows Vista was introduced on 11/08/2006 in Windows Vista. The most recent version [file version 10] was introduced on 07/29/2015 for Windows 10. RegAsm.exe is bundled with the software package in Windows 10, Windows 8.1, and Windows 8.
Windows Vista的RegAsm.exe的第一版于2006年11月8日在Windows Vista中引入。 Windows 10的最新版本(文件版本10)已于07/29/2015引入。RegAsm.exe与Windows 10,Windows 8.1和Windows 8中的软件包捆绑在一起。
Please see below for more detailed information, EXE file troubleshooting instructions, and free downloads of different versions of RegAsm.exe.
请参阅下面的详细信息,EXE文件故障排除说明以及RegAsm.exe不同版本的免费下载。
作用: 读取程序集中的元数据,并将所需的项添加到注册表中。注册表允许 COM 客户程序以透明方式创建 .NET Framework 类。类一经注册,任何 COM 客户程序都可以使用它,就好像该类是一个 COM 类。类仅在安装程序集时注册一次。程序集中的类实例直到被实际注册时,才能从 COM 中创建。
作用: Regsvr32命令用于注册COM组件,是 Windows 系统提供的用来向系统注册控件或者卸载控件的命令,以命令行方式运行。WinXP及以上系统的regsvr32.exe在windows\system32文件夹下;2000系统的regsvr32.exe在winnt\system32文件夹下。
regsvr32 will load the library and try to call the DllRegisterServer() from that library. It doesn’t care what DllRegisterServer() actually does - it just calls that function and checks the returned value. You use it to register COM servers in unmanaged DLLs. It can’t generate a .tlb file.
regasm will register a COM-exposed .NET assembly as a COM server. You use it for .NET assemblies. It can generate a .tlb file given the assembly only - it inspects the type infromation stored in the assembly and includes the COM-exposed entities into the type library.
[Run] ; Regist the .NET DLL file by using the tool regasm.exe, return 0: ERROR_SUCCESS; 1:ERROR_INVALID_FUNCTION; 2:ERROR_FILE_NOT_FOUND; 3: ERROR_PATH_NOT_FOUND Filename: {code:GetCurrentRegAsmPath|{#DotNetRegistToolPath}}\regasm.exe; Parameters: " ""{commonappdata}\{#********AppPath}\bin\NET\xxxxxxxxxxxxxxxxxxx.dll"" /codebase /verbose"; WorkingDir: "{commonappdata}\{#********AppPath}\bin\NET\"; StatusMsg: Registering DLLs; Flags: 64bit runhidden waituntilterminated;
[UninstallRun] ; Regist the .NET DLL file by using the tool regasm.exe, return 0: ERROR_SUCCESS; 1:ERROR_INVALID_FUNCTION; 2:ERROR_FILE_NOT_FOUND; 3: ERROR_PATH_NOT_FOUND Filename: {code:GetCurrentRegAsmPath|{#DotNetRegistToolPath}}\regasm.exe; Parameters: "/unregister ""{commonappdata}\{#********AppPath}\bin\NET\xxxxxxxxxxxxxxxxxxx.dll"" /codebase /verbose"; WorkingDir: "{commonappdata}\{#********AppPath}\bin\NET\"; StatusMsg: Unregistering DLLs; Flags: 64bit runhidden waituntilterminated;
[CustomMessages] ; .NET Framwork installation processing ENGLISH.DotNetFrameworkOfflineInstallerCaption = Installing Microsoft .NET framework %1 offline installer for Windows... ENGLISH.DotNetFrameworkWebInstallerCaption = Installing Microsoft .NET framework %1 Web installer for Windows... ENGLISH.DotNetFrameworkFailedToLaunch = .NET installation failed with code: %1. Please fix the error then run this installer again. ENGLISH.DotNetFrameworkFailed1602 = .NET Framework installation was cancelled. This installation can continue, but be aware that this application may not run unless the .NET Framework installation is completed successfully. ENGLISH.DotNetFrameworkFailed1603 = A fatal error occurred while installing the .NET Framework. Please fix the error, then run the installer again. ENGLISH.DotNetFrameworkFailed5100 = Your computer does not meet the requirements of the .NET Framework. Please consult the documentation. ENGLISH.DotNetFrameworkFailedOther = The .NET Framework installer exited with an unexpected status code "%1". Please review any other messages shown by the installer to determine whether the installation completed successfully, and abort this installation and fix the problem if it did not.
; .NET Framwork installation processing DEUTSCH.DotNetFrameworkOfflineInstallerCaption = Installation von Microsoft .NET Framework %1 offline Installationsprogramm für Windows ... DEUTSCH.DotNetFrameworkWebInstallerCaption = Installation von Microsoft .NET Framework %1 Web Installationsprogramm für Windows ... DEUTSCH.DotNetFrameworkFailedToLaunch = .NET Installation fehlgeschlagen mit Code: %1. Bitte beheben Sie den Fehler und führen Sie das Installationsprogramm erneut aus. DEUTSCH.DotNetFrameworkFailed1602 = .NET Framework-Installation wurde abgebrochen. Diese Installation kann fortgesetzt werden. Beachten Sie jedoch, dass diese Anwendung möglicherweise erst ausgeführt wird, wenn die .NET Framework-Installation erfolgreich abgeschlossen wurde. DEUTSCH.DotNetFrameworkFailed1603 = Bei der Installation von .NET Framework ist ein schwerwiegender Fehler aufgetreten. Bitte beheben Sie den Fehler und führen Sie das Installationsprogramm erneut aus. DEUTSCH.DotNetFrameworkFailed5100 = Ihr Computer entspricht nicht den Anforderungen von .NET Framework. Bitte konsultieren Sie die Dokumentation. DEUTSCH.DotNetFrameworkFailedOther = Das .NET Framework-Installationsprogramm wurde mit dem unerwarteten Statuscode "%1" beendet. Überprüfen Sie alle anderen vom Installationsprogramm angezeigten Meldungen, um festzustellen, ob die Installation erfolgreich abgeschlossen wurde, und brechen Sie diese Installation ab, und beheben Sie das Problem, wenn dies nicht der Fall ist.
var bCancelWithoutPrompt: boolean; bConnectWithNetwork: boolean; bRequiresRestart: boolean;
functionGetCurrentRegAsmPath(S: String):String; var version: String; key: String; installPath: String; success: boolean; begin Result := S; // .NET 4.6.2 installs also as update to .NET 4.0 Full, you can also be on the safe side, check the windows 10 anniversary update // if the build was newer than (build 10.0.14393) with the code GetWindowsVersion >= $A003839 if TO_COMPARE_DOT_NET = 'v4.6.2'thenbegin version := 'v4\Full'; end; // .NET 4.5 installs as update to .NET 4.0 Full if TO_COMPARE_DOT_NET = 'v4.5'thenbegin version := 'v4\Full'; end; // installation key group for all .NET versions key := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\' + version; success := RegQueryStringValue(HKLM, key, 'InstallPath', installPath); if (success = True) and (S = '') then begin Result := installPath; end end;
functionInstallFrameworkWebRuntime():String; var WasVisible: Boolean; ResultCode: Integer; begin ExtractTemporaryFile('{#DotNetFrameWorkWebInstaller}'); WasVisible := WizardForm.PreparingLabel.Visible; try WizardForm.PreparingLabel.Visible := True; WizardForm.PreparingLabel.Caption := FmtMessage(CustomMessage('DotNetFrameworkWebInstallerCaption'), [TO_COMPARE_DOT_NET]); ExtractTemporaryFile('{#DotNetFrameWorkWebInstaller}'); //if not Exec(ExpandConstant('{tmp}\{#DotNetFrameWorkWebInstaller}'), '/q /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then ifnot Exec(ExpandConstant('{tmp}\{#DotNetFrameWorkWebInstaller}'), '/passive /norestart /showrmui /showfinalerror', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin // https://docs.microsoft.com/de-de/windows/win32/debug/system-error-codes--0-499- // you can interact with the user that the installation failed, for example: error code 2: the system cannot find the file specified. Result := FmtMessage(CustomMessage('DotNetFrameworkFailedToLaunch'), [SysErrorMessage(ResultCode)]) end else begin case ResultCode of 0: begin // Successful end; 1602 : begin MsgBox(CustomMessage('DotNetFrameworkFailed1602'), mbInformation, MB_OK); end; 1603: begin Result := CustomMessage('DotNetFrameworkFailed1603'); end; 1641: begin bRequiresRestart := True; end; 3010: begin bRequiresRestart := True; end; 5100: begin Result := CustomMessage('DotNetFrameworkFailed5100'); end; elsebegin //MsgBox(FmtMessage(CustomMessage('DotNetFrameworkFailedOther'), [IntToStr(resultCode)]), mbError, MB_OK); Result := FmtMessage(CustomMessage('DotNetFrameworkFailedOther'), IntToStr(ResultCode)); end; end; end; finally WizardForm.PreparingLabel.Visible := WasVisible; end; DeleteFile(ExpandConstant('{tmp}\{#DotNetFrameWorkWebInstaller}')); end;
functionInstallFrameworkOfflineRuntime():String; var WasVisible: Boolean; ResultCode: Integer; begin WasVisible := WizardForm.PreparingLabel.Visible; try WizardForm.PreparingLabel.Visible := True; WizardForm.PreparingLabel.Caption := FmtMessage(CustomMessage('DotNetFrameworkOfflineInstallerCaption'), [TO_COMPARE_DOT_NET]); ExtractTemporaryFile('{#DotNetFrameWorkOfflineInstaller}'); //if not Exec(ExpandConstant('{tmp}\{#DotNetFrameWorkOfflineInstaller}'), '/q /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then ifnot Exec(ExpandConstant('{tmp}\{#DotNetFrameWorkOfflineInstaller}'), '/passive /norestart /showrmui /showfinalerror', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin // https://docs.microsoft.com/de-de/windows/win32/debug/system-error-codes--0-499- // you can interact with the user that the installation failed, for example: error code 2: the system cannot find the file specified. Result := FmtMessage(CustomMessage('DotNetFrameworkFailedToLaunch'), [SysErrorMessage(ResultCode)]) end else begin case ResultCode of 0: begin // Successful end; 1602 : begin MsgBox(CustomMessage('DotNetFrameworkFailed1602'), mbInformation, MB_OK); end; 1603: begin Result := CustomMessage('DotNetFrameworkFailed1603'); end; 1641: begin bRequiresRestart := True; end; 3010: begin bRequiresRestart := True; end; 5100: begin Result := CustomMessage('DotNetFrameworkFailed5100'); end; elsebegin //MsgBox(FmtMessage(CustomMessage('DotNetFrameworkFailedOther'), [IntToStr(resultCode)]), mbError, MB_OK); Result := FmtMessage(CustomMessage('DotNetFrameworkFailedOther'), IntToStr(ResultCode)); end; end; end; finally WizardForm.PreparingLabel.Visible := WasVisible; end; DeleteFile(ExpandConstant('{tmp}\{#DotNetFrameWorkOfflineInstaller}')); end;
functionIsNetWorkActivatedTried: boolean; var WinHttpReq: Variant; Connected: Boolean; iTriedTime: Integer; begin Connected := False; iTriedTime := 0; repeat iTriedTime := iTriedTime + 1; Log('Checking connection to the server, try ' + + IntToStr(iTriedTime) + ' time.'); try WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1'); WinHttpReq.SetTimeouts('3000', '3000', '3000', '3000'); // Use your real server host name WinHttpReq.Open('GET', 'https://www.camtek.de/', False); WinHttpReq.Send(''); Log('Connected to the server; status: ' + IntToStr(WinHttpReq.Status) + ' ' + WinHttpReq.StatusText); Connected := True; except Log('Error connecting to the server, msg: ' + GetExceptionMessage + 'try again! '); end; until (iTriedTime = 3) or (Connected = True) ; Result := Connected; end;
functionIsDotNetDetected(version: string; service: cardinal): boolean; // Indicates whether the specified version and service pack of the .NET Framework is installed. // see the link: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed?redirectedfrom=MSDN#net_b // // version -- Specify one of these strings for the required .NET Framework version: // 'v1.1.4322' .NET Framework 1.1 // 'v2.0.50727' .NET Framework 2.0 // 'v3.0' .NET Framework 3.0 // 'v3.5' .NET Framework 3.5 // 'v4\Client' .NET Framework 4.0 Client Profile // 'v4\Full' .NET Framework 4.0 Full Installation // 'v4.5' .NET Framework 4.5 378389 // 'v4.6' .NET Framework 4.6 393295 // 'v4.6.1' .NET Framework 4.6.1 394254 // 'v4.6.2' .NET Framework 4.6.2 394802 // 'v4.7' .NET Framework 4.7 393295 // // service -- Specify any non-negative integer for the required service pack level: // 0 No service packs required // 1, 2, etc. Service pack 1, 2, etc. required var key: string; install, release, serviceCount: cardinal; check45, check462, success: boolean; begin
// .NET 4.6.2 installs also as update to .NET 4.0 Full, you can also be on the safe side, check the windows 10 anniversary update // if the build was newer than (build 10.0.14393) with the code GetWindowsVersion >= $A003839 if version = 'v4.6.2'thenbegin version := 'v4\Full'; check462 := true; endelse check462 := false;
// .NET 4.5 installs as update to .NET 4.0 Full if version = 'v4.5'thenbegin version := 'v4\Full'; check45 := true; endelse check45 := false;
// installation key group for all .NET versions key := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\' + version;
// .NET 3.0 uses value InstallSuccess in subkey Setup if Pos('v3.0', version) = 1thenbegin success := RegQueryDWordValue(HKLM, key + '\Setup', 'InstallSuccess', install); endelsebegin success := RegQueryDWordValue(HKLM, key, 'Install', install); end;
// .NET 4.0/4.5 uses value Servicing instead of SP if Pos('v4', version) = 1thenbegin success := success and RegQueryDWordValue(HKLM, key, 'Servicing', serviceCount); endelsebegin success := success and RegQueryDWordValue(HKLM, key, 'SP', serviceCount); end;
// .NET 4.5 uses additional value Release if check45 thenbegin success := success and RegQueryDWordValue(HKLM, key, 'Release', release); success := success and (release >= 378389); end;
// .NET 4.6.2 uses additional value Release if check462 thenbegin success := success and RegQueryDWordValue(HKLM, key, 'Release', release); success := success and (release >= 394802); end;
Result := success and (install = 1) and (serviceCount >= service); end;
functionIsRequiredDotNetDetected: Boolean; begin Result := IsDotNetDetected(TO_COMPARE_DOT_NET, 0); end;
functionInstallDotNetOfflineRuntime: Boolean; begin ifnot bConnectWithNetwork then begin Result := True; end else begin if ActiveLanguage = 'ENGLISH'then begin Result := True; end else begin Result := False; end end end;
functionInstallDotNetWebRuntime: Boolean; begin if (not bConnectWithNetwork) and ( not ActiveLanguage = 'ENGLISH') then begin Result := True; end else begin Result := False; end end;
functionInitializeSetup(): Boolean; begin bConnectWithNetwork := IsNetWorkActivatedTried; Result := True; end;
functionPrepareToInstall(var NeedsRestart: Boolean):String; var bInstallWeb: boolean; bInstallStd: boolean; begin // 'NeedsRestart' only has an effect if we return a non-empty string, thus aborting the installation. // If the installers indicate that they want a restart, this should be done at the end of installation. // Therefore we set the global 'restartRequired' if a restart is needed, and return this from NeedRestart() bCancelWithoutPrompt := false; ifnot IsRequiredDotNetDetected then begin bInstallWeb := InstallDotNetWebRuntime; bInstallStd := InstallDotNetOfflineRuntime; if ( bInstallWeb = True) then begin Result := InstallFrameworkWebRuntime end elseif ( bInstallStd = True) then begin Result := InstallFrameworkOfflineRuntime end else begin Result := InstallFrameworkWebRuntime end; end; end;
functionNeedRestart(): Boolean; begin Result := bRequiresRestart; end;