Undo / TYPE and / COMPONENTS option on upgrade
In the case of an update / reinstall, is there a way to reset the value of the parameter /TYPE
and /COMPONENTS
passed on the command line to the installer and use the previously used values โโinstead? I can read the values โโused previously from the registry (or, alternatively, drill down based on the existence of the files, assuming they have not been manually modified).
I have read the following topics and can disable the Select Components page in UI mode
- Inno Setup Skip "Select Components" page when command line parameter / type is specified
- InnoSetup: disable component page on refresh
However, if the above options are passed from the command line, they seem to override the defaults.
source to share
You cannot undo them.
What you can do is check if these parameters were provided and if they were:
- Run the installer without them (see below) or
- Read the previously selected type and components from the registry and adjust the controls accordingly.
Restarting the installer without /TYPE=
and/COMPONENTS=
const UninstallKey = 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1'; function IsUpgrade: Boolean; var Value: string; begin Result := (RegQueryStringValue(HKLM, UninstallKey, 'UninstallString', Value) or RegQueryStringValue(HKCU, UninstallKey, 'UninstallString', Value)) and (Value <> ''); end; function ShellExecute(hwnd: HWND; lpOperation: string; lpFile: string; lpParameters: string; lpDirectory: string; nShowCmd: Integer): THandle; external 'ShellExecuteW@shell32.dll stdcall'; function InitializeSetup(): Boolean; var Params, S: string; Relaunch: Boolean; I, RetVal: Integer; begin Result := True; if IsUpgrade then begin Relaunch := False; { Collect current instance parameters } for I := 1 to ParamCount do begin S := ParamStr(I); if (CompareText(Copy(S, 1, 7), '/TYPES=') = 0) or (CompareText(Copy(S, 1, 12), '/COMPONENTS=') = 0) then begin Log(Format('Will re-launch due to %s', [S])); Relaunch := True; end else begin { Unique log file name for the child instance } if CompareText(Copy(S, 1, 5), '/LOG=') = 0 then begin S := S + '-sub'; end; { Do not pass our /SL5 switch } if CompareText(Copy(S, 1, 5), '/SL5=') <> 0 then begin Params := Params + AddQuotes(S) + ' '; end; end; end; if not Relaunch then begin Log('No need to re-launch'); end else begin Log(Format('Re-launching setup with parameters [%s]', [Params])); RetVal := ShellExecute(0, '', ExpandConstant('{srcexe}'), Params, '', SW_SHOW); Log(Format('Re-launching setup returned [%d]', [RetVal])); Result := (RetVal > 32); { if re-launching of this setup succeeded, then... } if Result then begin Log('Re-launching succeeded'); { exit this setup instance } Result := False; end else begin Log(Format('Elevation failed [%s]', [SysErrorMessage(RetVal)])); end; end; end; end;
The code is for Unicode version of Inno Setup.
The code could be further improved so that the installer does not wait for the installer to finish installing. When that might change, especially if the installer is running some kind of automated deployment process.
source to share