I know there is the WizardSilent function for checking whether the setup runs in silent mode, but I cannot find a function equivalent for very silent mode (when the setup is executed with /VERYSILENT command line parameter).
Is there a way to detect whether the setup runs in very silent mode?
WizardSilent will be true for both /Silent and /VerySilent installs. The difference between the two parameters is whether a progress bar is shown (/Silent) or not (/VerySilent).
Based on your comment, the best I can suggest would be to check the command line and look for /VerySilent and set a global variable. Something like:
[Code]
var
isVerySilent: Boolean;
function InitializeSetup(): Boolean;
var
j: Integer;
begin
isVerySilent := False;
for j := 1 to ParamCount do
if CompareText(ParamStr(j), '/verysilent') = 0 then
begin
isVerySilent := True;
Break;
end;
if isVerySilent then
Log ('VerySilent')
else
Log ('not VerySilent');
end;
This one works better... its compatible with multiple params in command line
var
j: Cardinal;
begin
isVerySilent := false;
begin
for j := 0 to ParamCount do
begin
MsgBox('param'+ParamStr(j), mbInformation, MB_OK);
if ParamStr(j)='/verysilent' then
isVerySilent := true;
end;
if isVerySilent then begin
Log ('VerySilent')
end else
Log ('not VerySilent');
end;
Related
I have a custom uninstall page, which is invoked with this line:
UninstallProgressForm.InnerNotebook.ActivePage := UninstallConfigsPage;
Now, this just shows the page every time the uninstaller is run, but I need it to show only if certain folders exist (there's 6 of them). I could make an if statement with a bunch of or's, but I'm wondering if there's a neater way to do it.
In general, there's no better way than calling DirExists for each folder:
if DirExists('C:\path1') or
DirExists('C:\path2') or
DirExists('C:\path3') then
begin
{ ... }
end;
Though, when processing a set of files/folders, it's advisable to have their list stored in some container (like TStringList or array of string), to allow their (repeated) bulk-processing. You already have that (Dirs: TStringList) from my solution to your other question.
var
Dirs: TStringList;
begin
Dirs := TStringList.Create();
Dirs.Add('C:\path1');
Dirs.Add('C:\path2');
Dirs.Add('C:\path2');
end;
function AnyDirExists(Dirs: TStringList): Boolean;
var
I: Integer;
begin
for I := 0 to Dirs.Count - 1 do
begin
if DirExists(Dirs[I]) then
begin
Result := True;
Exit;
end;
end;
Result := False;
end;
But I know from your other question, that you map all the paths to checkboxes. Hence, all you need to do, is to check, if there's any checkbox:
if CheckListBox.Items.Count > 0 then
begin
UninstallProgressForm.InnerNotebook.ActivePage := UninstallConfigssPage;
{ ... }
if UninstallProgressForm.ShowModal = mrCancel then Abort;
{ ... }
UninstallProgressForm.InnerNotebook.ActivePage := UninstallProgressForm.InstallingPage;
end;
I am trying to do something similar to this.
Do a version check after Welcome page is displayed
Display a message box (with mbInformation, MB_OK) in case of downgrade and exit
This works in UI mode - installer exits. However, in /Silent mode, it shows the message box but goes ahead after clicking the Ok button.
Can you please suggest how to achieve similar functionality in silent mode (i.e. gracefully exit the setup)
There's no difference in a the silent mode for implementing prerequisites check. Just test your prerequisites in the InitializeSetup event function, and return False, if you want to stop the installation.
The only things to consider for silent installations are:
Using the SuppressibleMsgBox function for error messages, instead of the plain MsgBox. This way the message can be suppressed with the /suppressmsgboxes command-line switch.
Do not display the message box at all for very silent installations (/verysilent).
See also How to detect whether the setup runs in very silent mode?
function WizardVerySilent: Boolean;
var
i: Integer;
begin
Result := False;
for i := 1 to ParamCount do
if CompareText(ParamStr(i), '/verysilent') = 0 then
begin
Result := True;
Break;
end;
end;
function InitializeSetup(): Boolean;
var
Message: string;
begin
Result := True;
if IsDowngrade then
begin
Message := 'Downgrade detected, aborting installation';
if not WizardVerySilent then
begin
SuppressibleMsgBox(Message, mbError, MB_OK, IDOK);
end
else
begin
Log(Message);
end;
Result := False;
end;
end;
Basically what I'm trying to achieve is the following:
If the user run the setup with the /SILENT or /VERYSILENT parameters, the setup will immediately present the EULA. If the user rejects, the install is canceled. If the user accepts, the rest of the install will happen in silent or verysilent mode.
Edit: both solutions presented by RobeN and TLama worked perfectly. The only problem is when the EULA is too big to fit a Message Box (that would be the most common situation). Anyway that's a good solution to at least display some warning or information before the install begins.
Simple solution - probably not the best, but quite fast.
Based on How to detect whether the setup runs in very silent mode?
[Files]
Source: "EULA_ANSI.txt"; DestDir: "{tmp}"; Flags: dontcopy nocompression
[Code]
var
isSilent: Boolean;
EULAText: AnsiString;
function InitializeSetup(): Boolean;
var
j: Integer;
begin
result := true;
isSilent := False;
for j := 1 to ParamCount do
if (CompareText(ParamStr(j), '/verysilent') = 0) or
(CompareText(ParamStr(j), '/silent') = 0) then
begin
isSilent := True;
Break;
end;
if isSilent then begin
ExtractTemporaryFile('EULA_ANSI.TXT');
if LoadStringFromFile(ExpandConstant('{tmp}\EULA_ANSI.txt'),
EULAText) then
begin
if MsgBox(EULAText, mbConfirmation, MB_YESNO) = IDNO then
result := false;
end
else begin
MsgBox('Unable to display EULA.' + #13#10 + #13#10 +
'Installation terminated!', mbCriticalError, MB_OK);
result := false;
end;
end
else begin
MsgBox(ExpandConstant('Standard Installation'), mbInformation,
MB_OK);
end;
end;
I do not think you can do that directly.
But you can introduce another command-line option, like /AUTOMATIC, that does what you need.
[Code]
function ShouldSkipPage(PageID: Integer): Boolean;
begin
Result :=
(Pos('/AUTOMATIC', Uppercase(GetCmdTail())) > 0) and
(PageID <> wpLicense);
end;
Is it possible to disable the the Preparing To Install wpPreparing and the Installing wpInstalling Wizard Pages (i.e. the ones with the progress bar) so that they do not show during installation? There does not appear to be a built-in directive or method (e.g. for the Ready Wizard Page you can use DisableReadyPage=yes to do so). Am I missing something, or is it, as I suspect, simply not possible?
I have already tried using:
function ShouldSkipPage(CurPageID: Integer): Boolean;
begin
if CurPageID = wpPreparing then
Result := True;
if CurPageID = wpInstalling then
Result := True;
end;
Have you tried this - DisableReadyPage=yes in the [Setup] section.
Seems the only other option is to use the "install silently" command line switch. I'd be careful though this essentially installs a potentially destructive program without the users knowledge.
It is not possible to skip the wpPreparing or wpInstalling Wizard Pages. However, if the installer is not actually installing anything and is being used to return something, say an unlock code, as is the use case here, the following could be done instead:
//Disable the Exit confirmation prompt
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
Cancel := True;
Confirm := False;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
//Get the unlock code
if CurPageID = UnlockCodePage.ID then
begin
if UnlockCodePage.Values[0] = '' then
begin
MsgBox('You must enter an installation ID to generate an unlock code.',
mbError, MB_OK);
end
else
begin
UnlockCodePage.Values[1] := GetUnlockCode;
end;
Result := False;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
//Define button visibility, whether the Back button is enabled and change the Next and Cancel button labels
WizardForm.CancelButton.Caption := '&Close';
if CurPageID = UnlockCodePage.ID then
begin
WizardForm.BackButton.Enabled := False;
WizardForm.NextButton.Caption := '&Generate';
end;
end;
Hopefully this may help someone looking to do something similar.
I try to making setup file to patch previous program. The setup must be able to check if previous program is installed or not.
This is my unusable code
[Code]
function GetHKLM() : Integer;
begin
if IsWin64 then
begin
Result := HKLM64;
end
else
begin
Result := HKEY_LOCAL_MACHINE;
end;
end;
function InitializeSetup(): Boolean;
var
V: string;
begin
if RegKeyExists(GetHKLM(), 'SOFTWARE\ABC\Option\Settings')
then
MsgBox('please install ABC first!!',mbError,MB_OK);
end;
My condition is
must check windows 32- or 64-bits in for RegKeyExists
if previous program is not installed, show error message and exit setup program, else continue process.
How to modify the code?
Thank you in advance.
**Update for fix Wow6432Node problem. I try to modify my code
[Code]
function InitializeSetup: Boolean;
begin
// allow the setup to continue initially
Result := True;
// if the registry key based on current OS bitness doesn't exist, then...
if IsWin64 then
begin
if not RegKeyExists(HKLM, 'SOFTWARE\Wow6432Node\ABC\Option\Settings') then
begin
// return False to prevent installation to continue
Result := False;
// and display a message box
MsgBox('please install ABC first!!', mbError, MB_OK);
end
else
if not RegKeyExists(HKLM, 'SOFTWARE\ABC\Option\Settings' then
begin
// return False to prevent installation to continue
Result := False;
// and display a message box
MsgBox('please install ABC first!!', mbError, MB_OK);
end
end;
end;
The updated code in the question is incorrect -- you should never ever use Wow6432Node anywhere other than when looking at paths in RegEdit.
From the behaviour you have described, you are actually looking for a 32-bit application. In this case you can use the same code regardless of whether Windows is 32-bit or 64-bit; you were overthinking your original question.
Here is the corrected code from your updated question:
[Code]
function InitializeSetup: Boolean;
begin
// allow the setup to continue initially
Result := True;
if not RegKeyExists(HKLM, 'SOFTWARE\ABC\Option\Settings') then
begin
// return False to prevent installation to continue
Result := False;
// and display a message box
MsgBox('please install ABC first!!', mbError, MB_OK);
end;
end;