call RegQueryDWordValue to get office Excel Version using inno Setup installer - excel

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

Related

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;

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

Use a part of a registry key/value in the Inno Setup script

I have a need to retrieve a path to be used for some stuffs in the installer according an other application previously installed on the system.
This previous application hosts a service and only provides one registry key/value hosting this information: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\APPLICATION hosting the value ImagePath which Data is "E:\TestingDir\Filename.exe".
I need a way to only extract the installation path (E:\TestingDir) without the Filename.exe file.
Any suggestion?
thanks a lot
You can achieve this using a scripted constant.
You define a function that produces the value you need:
[Code]
function GetServiceInstallationPath(Param: string): string;
var
Value: string;
begin
if RegQueryStringValue(
HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Services\APPLICATION',
'ImagePath', Value) then
begin
Result := ExtractFileDir(Value);
end
else
begin
Result := { Some fallback value }
end;
end;
And then you refer to it using {code:GetServiceInstallationPath} where you need it (like in the [Run] section).
For example:
[Run]
Filename: "{code:GetServiceIntallationPath}\SomeApp.exe"
Actually, you probably want to retrieve the value in InitializeSetup already, and cache the value in a global variable for use in the scripted constant. And abort the installation (by returning False from InitializeSetup), in case the other application is not installed (= the registry key does not exist).
[Code]
var
ServiceInstallationPath: string;
function InitializeSetup(): Boolean;
var
Value: string;
begin
if RegQueryStringValue(
HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Services\APPLICATION',
'ImagePath', Value) then
begin
ServiceInstallationPath := ExtractFileDir(Value);
Log(Format('APPLICATION installed to %s', [ServiceInstallationPath]));
Result := True;
end
else
begin
MsgBox('APPLICATION not installed, aborting installation', mbError, MB_OK);
Result := False;
end;
end;
function GetServiceInstallationPath(Param: string): string;
begin
Result := ServiceInstallationPath;
end;
See also a similar question: Using global string script variable in Run section in Inno Setup.
Solved this way:
[code]
var
ServiceInstallationPath: string;
function MyProgCheck(): Boolean;
var
Value: string;
begin
if RegQueryStringValue(
HKEY_LOCAL_MACHINE, 'SYSTEM\ControlSet001\Services\JLR STONE VCATS TO MES',
'ImagePath', Value) then
begin
ServiceInstallationPath := ExtractFileDir(Value);
Result := True;
end
else
begin
Result := False;
end;
end;
and in the [RUN] section I put as check the TRUE condition or FALSE condition on this function according the needs...Thanks everybody answering!

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

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.

Inno Setup, show a msgbox on the folder selection step

I am trying to display a message box only when the user reach the folder selection page, here are the actual code that display the message box at the beginning of the setup:
[code]
var ApplicationPath: string;
function GetAppPath(Param: String): String;
begin
RegQueryStringValue(HKLM, 'SOFTWARE\XXX\XXX', 'Install Dir', ApplicationPath)
if ApplicationPath = '' then
begin
MsgBox('Install folder non found', mbError, MB_OK);
result:=ApplicationPath;
end
else
MsgBox('Install folder found in "' + ApplicationPath + '". NOTE: close the program before proceeding.', mbInformation, MB_OK);
result:=ApplicationPath;
end;
end.
I need something like:
If (PageId = wpSelectDir) then...
[run the above code]
but really I don't know how, thanks for your help.
The ideal event for this is the CurPageChanged. You can use it this way to run a code, when the select directory page is shown:
[Code]
procedure CurPageChanged(CurPageID: Integer);
var
AppPath: string;
begin
if (CurPageID = wpSelectDir) then
begin
// this will query the string value in registry; if that succeed and the
// value is read, then the message box about success is shown, otherwise
// the error message box about failure is shown
if RegQueryStringValue(HKLM, 'SOFTWARE\XXX\XXX', 'Install Dir', AppPath) then
MsgBox('Installation folder found...', mbInformation, MB_OK)
else
MsgBox('Installation folder not found...', mbError, MB_OK);
end;
end;

Resources