How do I check if registry key exists and exit setup - inno-setup

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;

Related

Inno setup asking for remove folder only if contain files [duplicate]

I have written a setup. In this setup nothing happens, because I only concentrated on one area: The "
wpSelectDir", where the user can choose a directory the setup should be installed in.
Now my code snippet should check, if ANYTHING exist in the chosen directory (any other folders, files, etc.). If so, the user gets warned if he still wants to continue, because everything in this directory will be removed then.
If the user only created a new empty folder he should not get a warning, because nothing will be lost.
I have the code snippet already finished excepting the check if the directory is empty (I replaced it with "if 1=1 then".
Please just have a look:
[Setup]
AppName=Testprogramm
AppVerName=Example
AppPublisher=Exxample
DefaultDirName={pf}\C
DefaultGroupName=C
Compression=lzma
SolidCompression=yes
[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if CurPageID = wpSelectDir then // if user is clicked the NEXT button ON the select directory window; if1 begins here;
begin
if 1=1 then // if the directory is not empty; thx 4 help stackoverflow
begin // warning with yes and no
if MsgBox('The file contains data. This data will be removed permanently by continuing the setup?', mbConfirmation, MB_YESNO) = IDYES then //if 3 begins here
begin
Result := True;
end
else
begin
Result := False;
end;
end; // if2 ends here
end // not CurPageID but any other begins here
else
begin
Result := True;
end;
end;
I have already tried to use functions like "if FileExists( ...", but there I can not say " . " for any file. Also I was not successful using WizardDirValue and its properties.
I would really appreciate if someone could help me or give me a hint.
Thanks a lot,
Regards C.
Use FindFirst/FindNext.
Example:
function isEmptyDir(dirName: String): Boolean;
var
FindRec: TFindRec;
FileCount: Integer;
begin
Result := False;
if FindFirst(dirName+'\*', FindRec) then begin
try
repeat
if (FindRec.Name <> '.') and (FindRec.Name <> '..') then begin
FileCount := 1;
break;
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
if FileCount = 0 then Result := True;
end;
end;
end;
Note: This function also returns False if directory doesn't exists

How to exit from installation in silent mode based on a check after InitializeSetup

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;

Is it possible to display the EULA and then run the setup with /SILENT or /VERYSILENT parameter?

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;

Inno Setup disable Installing Wizard Pages

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.

How to detect whether the setup runs in very silent mode?

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;

Resources