@@ -74,46 +74,60 @@ Name: "{group}\{cm:UninstallProgram,{#AppName}}"; Filename: "{uninstallexe}"
74
74
const
75
75
SCS_32BIT_BINARY = 0 ;
76
76
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
+
79
80
var
80
81
HasCheckedOfficeBitness: Boolean;
81
82
OfficeIs64Bit: Boolean;
82
83
83
84
function GetBinaryType (lpApplicationName: AnsiString; var lpBinaryType: Integer): Boolean;
84
85
external ' GetBinaryTypeA@kernel32.dll stdcall' ;
85
86
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;
88
88
var
89
- excelPath : String;
89
+ appPath : String;
90
90
binaryType: Integer;
91
91
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
100
97
try
101
- if GetBinaryType(excelPath, binaryType) then begin
102
- Result := (binaryType = SCS_64BIT_BINARY);
103
- end ;
98
+ if GetBinaryType(appPath, binaryType) then Result := binaryType;
104
99
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.
109
100
end ;
110
101
end ;
111
102
end ;
112
103
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
+
113
127
function Is64BitOfficeInstalled (): Boolean;
114
128
begin
115
129
if (not HasCheckedOfficeBitness) then
116
- OfficeIs64Bit := Is64BitExcelFromRegisteredExe( );
130
+ OfficeIs64Bit := (GetOfficeBitness() = SCS_64BIT_BINARY );
117
131
Result := OfficeIs64Bit;
118
132
end ;
119
133
0 commit comments