Skip to content

Commit 3939297

Browse files
author
Ross Knudsen
committed
Modified the method for checking which bitness of Office is installed to check other office apps besides Excel.
1 parent e8d2104 commit 3939297

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

Installer Build Script.iss

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,46 +74,60 @@ Name: "{group}\{cm:UninstallProgram,{#AppName}}"; Filename: "{uninstallexe}"
7474
const
7575
SCS_32BIT_BINARY = 0;
7676
SCS_64BIT_BINARY = 6;
77-
// There are other values that GetBinaryType can return, but we're
78-
// not interested in them.
77+
// There are other values that GetBinaryType can return, but we're not interested in them.
78+
OfficeNotFound = -1;
79+
7980
var
8081
HasCheckedOfficeBitness: Boolean;
8182
OfficeIs64Bit: Boolean;
8283
8384
function GetBinaryType(lpApplicationName: AnsiString; var lpBinaryType: Integer): Boolean;
8485
external 'GetBinaryTypeA@kernel32.dll stdcall';
8586
86-
// TODO this only checks for Excel's bitness, but what if they don't have it installed?
87-
function Is64BitExcelFromRegisteredExe(): Boolean;
87+
function GetOfficeAppBitness(exeName: string): Integer;
8888
var
89-
excelPath: String;
89+
appPath: String;
9090
binaryType: Integer;
9191
begin
92-
Result := False; // Default value - assume 32-bit unless proven otherwise.
93-
// RegQueryStringValue second param is '' to get the (default) value for the key
94-
// with no sub-key name, as described at
95-
// http://stackoverflow.com/questions/913938/
96-
if IsWin64() and RegQueryStringValue(HKEY_LOCAL_MACHINE,
97-
'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe',
98-
'', excelPath) then begin
99-
// We've got the path to Excel.
92+
Result := OfficeNotFound; // Default value.
93+
94+
if RegQueryStringValue(HKEY_LOCAL_MACHINE,
95+
'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\' + exeName,
96+
'', appPath) then begin
10097
try
101-
if GetBinaryType(excelPath, binaryType) then begin
102-
Result := (binaryType = SCS_64BIT_BINARY);
103-
end;
98+
if GetBinaryType(appPath, binaryType) then Result := binaryType;
10499
except
105-
// Ignore - better just to assume it's 32-bit than to let the installation
106-
// fail. This could fail because the GetBinaryType function is not
107-
// available. I understand it's only available in Windows 2000
108-
// Professional onwards.
109100
end;
110101
end;
111102
end;
112103
104+
function GetOfficeBitness(): Integer;
105+
var
106+
appBitness: Integer;
107+
officeExeNames: array[0..4] of String;
108+
i: Integer;
109+
begin
110+
officeExeNames[0] := 'excel.exe';
111+
officeExeNames[1] := 'msaccess.exe';
112+
officeExeNames[2] := 'winword.exe';
113+
officeExeNames[3] := 'outlook.exe';
114+
officeExeNames[4] := 'powerpnt.exe';
115+
116+
for i := 0 to 4 do begin
117+
appBitness := GetOfficeAppBitness(officeExeNames[i]);
118+
if appBitness <> OfficeNotFound then begin
119+
Result := appBitness;
120+
exit;
121+
end;
122+
end;
123+
// Note if we get to here then we haven't found any Office versions. Should
124+
// we fail the installation?
125+
end;
126+
113127
function Is64BitOfficeInstalled(): Boolean;
114128
begin
115129
if (not HasCheckedOfficeBitness) then
116-
OfficeIs64Bit := Is64BitExcelFromRegisteredExe();
130+
OfficeIs64Bit := (GetOfficeBitness() = SCS_64BIT_BINARY);
117131
Result := OfficeIs64Bit;
118132
end;
119133

0 commit comments

Comments
 (0)