INNO - checking file is installed with function InitializeSetup(): Boolean; - inno-setup

I'm new to Inno, but want to check '{pf32}\Google\Drive\googledrivesync.exe' is installed before install.
However, the code does not pick up {pf32} as it does in Check: for a file.
New some can you assist please
Michael
[Code]
function InitializeSetup(): Boolean;
var FilePath3, FP1: String;
begin
//Result := FileExists(FilePath3);
//FP1:= {pf32} FilePath3:= '\Google\Drive\googledrivesync.exe'
if not FileExists({pf32} + FilePath3) Then
begin MsgBox({pf32} + FilePath3 + 'Google Drive not installed correctly - Setup will now exit - Please reinstall Google Drive!', mbError, MB_OK);
abort;
end;
end;

You have to use ExpandConstant in order to...well...expand constants. :-)
function InitializeSetup(): Boolean;
var
FilePath3: String;
PFDir: string;
begin
PFDir := ExpandConstant('{pf32}');
FilePath3:= '\Google\Drive\googledrivesync.exe'
Result := FileExists(PFDir + FilePath3);
if not Result then
begin
MsgBox(PFDir + FilePath3 + #13#13 +
'Google Drive not installed' +
'correctly - Setup will now exit.'#13 +
'Please reinstall Google Drive!', mbError, MB_OK);
Abort;
end;
end;
NOTE: I don't recall off-hand if ExpandConstant includes the trailing backslash or not, so you'll have to test. If so, you'll need to remove the backslash that starts FilePath3.

Related

Check installation path for spaces and special symbol in Inno Setup

I cannot find a solution for checking the user selected path to be without any spaces or special characters.
Can you help me?
You can check for space like this:
[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
var
Dir: string;
Msg: string;
begin
Result := True;
if CurPageID = wpSelectDir then
begin
Dir := WizardForm.DirEdit.Text;
if Pos(' ', Dir) > 0 then
begin
Msg := 'The path cannot contain spaces';
if WizardSilent then Log(Msg)
else MsgBox(Msg, mbError, MB_OK);
Result := False;
end;
end;
end;
You may consider using SuppressibleMsgBox function:
What does it mean that message boxes are being suppressed in Inno Setup?

Download additional files based on contents of first download using IDP

Want to download files based on contents of first download using Inno Download Plugin (IDP). How to do that?
Here is my code
[Code]
procedure InitializeWizard();
var
line: string;
line2: string;
url: string;
appname: string;
begin
idpAddFile('http://download.website.com/files.txt', ExpandConstant('{tmp}\files.txt'));
idpDownloadAfter(wpReady);
TryGetFileLine(expandConstant('{tmp}\files.txt'), 0, line);
TryGetFileLine(expandConstant('{tmp}\files.txt'), 1, line2);
url := line;
appname := line2;
idpAddFile(url, ExpandConstant('{tmp}\'+appname));
idpDownloadAfter(wpReady);
end;
Here second file starts downloading before the first file finishes. So how to make it one after another?
Tell IDP to only download the list initially. Then wait for the download to finish (for that see Running a program after it is downloaded in Code section in Inno Setup) and based on the results, create new download list and restart the download.
var
ListDownloaded: Boolean;
procedure InitializeWizard();
begin
idpAddFile('http://www.example.com/files.txt', ExpandConstant('{tmp}\files.txt'));
idpDownloadAfter(wpReady);
ListDownloaded := False;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
Url, AppName: string;
begin
Result := True;
if CurPageID = IDPForm.Page.ID then
begin
if not ListDownloaded then
begin
TryGetFileLine(ExpandConstant('{tmp}\files.txt'), 0, Url);
TryGetFileLine(ExpandConstant('{tmp}\files.txt'), 1, AppName);
idpClearFiles;
idpAddFile(Url, ExpandConstant('{tmp}\' + AppName));
idpFormActivate(nil); { This restarts the download }
Result := False;
ListDownloaded := True;
end;
end;
end;

Conditional reboot in innosetup installer [duplicate]

My Inno Setup script is used to install a driver. It runs my InstallDriver.exe after this file was copied during step ssInstall.
I need to ask the user to restart in some cases according to the value returned by InstallDriver.exe.
This means that I cannot put InstallDriver.exe in section [Run] because there's no way to monitor it's return value.
So I put it in function CurStepChanged() as follows:
procedure CurStepChanged(CurStep: TSetupStep);
var
TmpFileName, ExecStdout, msg: string;
ResultCode: Integer;
begin
if (CurStep=ssPostInstall) then
begin
Log('CurStepChanged(ssPostInstall)');
TmpFileName := ExpandConstant('{app}') + '\InstallDriver.exe';
if Exec(TmpFileName, 'I', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then .......
However, I can't find a way to make my script restart at this stage.
I thought of using function NeedRestart() to monitor the output of the driver installer, but it is called earlier in the process.
Does it make sense to call the driver installer from within NeedRestart()?
NeedRestart does not look like the right place to install anything. But it would work, as it's fortunately called only once. You will probably want to present a progress somehow though, as the wizard form is almost empty during a call to NeedRestart.
An alternative is to use AfterInstall parameter of the InstallDriver.exe or the driver binary itself (whichever is installed later).
#define InstallDriverName "InstallDriver.exe"
[Files]
Source: "driver.sys"; DestDir: ".."
Source: "{#InstallDriverName}"; DestDir: "{app}"; AfterInstall: InstallDriver
[Code]
var
NeedRestartFlag: Boolean;
const
NeedRestartResultCode = 1;
procedure InstallDriver();
var
InstallDriverPath: string;
ResultCode: Integer;
begin
Log('Installing driver');
InstallDriverPath := ExpandConstant('{app}') + '\{#InstallDriverName}';
if not Exec(InstallDriverPath, 'I', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
begin
Log('Failed to execute driver installation');
end
else
begin
Log(Format('Driver installation finished with code %d', [ResultCode]))
if ResultCode = NeedRestartResultCode then
begin
Log('Need to restart to finish driver installation');
NeedRestartFlag := True;
end;
end;
end;
function NeedRestart(): Boolean;
begin
if NeedRestartFlag then
begin
Log('Need restart');
Result := True;
end
else
begin
Log('Do not need restart');
Result := False;
end;
end;

Inno Setup: Check if file exists anywhere in C: drive

Some questions/solutions I found on here were similar but not quite what I needed.
I'm trying to create an installer for a Python application I've created for Windows. The installer calls another installer (openscad_installer.exe) and the user has the choice to install that wherever they like (i.e. I don't know the destination and would need to be able to find it) or not to install it at all.
I essentially need to check if the openscad.exe file exists (i.e. if it is installed) anywhere on the computer (in the C: drive) and if it does not exist then I need to uninstall my software.
The uninstall process seems simple enough but I don't know how to find out if the file exists. Thanks for the help.
Searching the file in C: drive (and possibly any other drive, as an user may choose to install a software anywhere else) is doable, but can take ages.
I'd suggest you instead check for an existence of the SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenSCAD registry key:
const
OpenSCADRegKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenSCAD';
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
ResultCode: integer;
begin
Exec('OpenSCAD-xxx-Installer.exe', '', '', SW_SHOW, ewWaitUntilTerminated,
ResultCode);
if RegKeyExists(HKEY_CURRENT_USER_32, OpenSCADRegKey) or
RegKeyExists(HKEY_CURRENT_USER_64, OpenSCADRegKey) or
RegKeyExists(HKEY_LOCAL_MACHINE_32, OpenSCADRegKey) or
RegKeyExists(HKEY_LOCAL_MACHINE_64, OpenSCADRegKey) then
begin
Log('OpenSCAD is installed');
end
else
begin
Log('OpenSCAD is not installed');
// Abort installation
Result := 'OpenSCAD is not installed';
Exit;
end;
end;
If you need to know the installation location, read and parse the UninstallString value:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenSCAD]
"UninstallString"="C:\\Program Files\\OpenSCAD\\Uninstall.exe"
If you insist on searching for openscad.exe use:
function FindFile(RootPath: string; FileName: string): string;
var
FindRec: TFindRec;
FilePath: string;
begin
Log(Format('Searching %s for %s', [RootPath, FileName]));
if FindFirst(RootPath + '\*', FindRec) then
begin
try
repeat
if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
begin
FilePath := RootPath + '\' + FindRec.Name;
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0 then
begin
Result := FindFile(FilePath, FileName);
if Result <> '' then Exit;
end
else
if CompareText(FindRec.Name, FileName) = 0 then
begin
Log(Format('Found %s', [FilePath]));
Result := FilePath;
Exit;
end;
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end
else
begin
Log(Format('Failed to list %s', [RootPath]));
end;
end;
Yet another option is looking for the file in search path:
How can I check SQLCMD.EXE if it is installed on client in Inno Setup

call RegQueryDWordValue to get office Excel Version using inno Setup installer

How do I get installed Version of MS office Excel from registry using inno Script? i tried bellow code,it gives 'Key not found' but it exist
function InitializeSetup(): Boolean;
var
CurVer: Cardinal;
key: string;
if RegQueryDWordValue(HKCR, 'Excel.Application\CurVer\','Default', CurVer) then
begin
// Successfully read the value
MsgBox('Excel Version: ' + IntTOStr(CurVer),mbInformation, MB_OK);
end else begin
MsgBox('Key not found',mbInformation, MB_OK);
end;
end;
changed RegQueryDWordValue to RegQueryStringValue
function InitializeSetup(): Boolean;
var
CurVer: Cardinal;
key: string;
begin
//if RegQueryDWordValue(HKCR, 'Excel.Application\\CurVer\\','', CurVer) then
if RegQueryStringValue(HKCR, 'Excel.Application\CurVer\','', key) then
begin
// Successfully read the value
MsgBox('Excel Version: ' + key,mbInformation, MB_OK);
end else begin
MsgBox('Excel Not installed',mbInformation, MB_OK);
end;
end;
Remove the trailing backslash.
Also, the (Default) value in RegEdit is the one with no name:
if RegQueryDWordValue(HKCR, 'Excel.Application\CurVer','', CurVer) then

Resources