@joebigelow / wix / commits / a96db4a5

Add registry bitness to RegUtil and BUtil.

Fixes https://github.com/wixtoolset/issues/issues/6669. Fixes https://github.com/wixtoolset/issues/issues/6670.

Bob Arnson committed Jan 9, 2022 at 23:23 UTC a96db4a508f1d1774500ab89f2c57e581fb5a13a
6 files changed +219 -138
src/burn/engine/registration.cpp
+8 -8
@@ -1742,38 +1742,38 @@ static BOOL IsRegistryRebootPending()
1742 HKEY hk = NULL;
1743 BOOL fRebootPending = FALSE;
1744
1745 - hr = RegKeyReadNumber(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\ServerManager", L"CurrentRebootAttempts", TRUE, &dwValue);
1745 + hr = RegKeyReadNumber(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\ServerManager", L"CurrentRebootAttempts", REG_KEY_DEFAULT, &dwValue);
1746 fRebootPending = SUCCEEDED(hr) && 0 < dwValue;
1747
1748 if (!fRebootPending)
1749 {
1750 - hr = RegKeyReadNumber(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Updates", L"UpdateExeVolatile", TRUE, &dwValue);
1750 + hr = RegKeyReadNumber(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Updates", L"UpdateExeVolatile", REG_KEY_DEFAULT, &dwValue);
1751 fRebootPending = SUCCEEDED(hr) && 0 < dwValue;
1752
1753 if (!fRebootPending)
1754 {
1755 - fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending", NULL, TRUE);
1755 + fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending", NULL, REG_KEY_DEFAULT);
1756
1757 if (!fRebootPending)
1758 {
1759 - fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootInProgress", NULL, TRUE);
1759 + fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootInProgress", NULL, REG_KEY_DEFAULT);
1760
1761 if (!fRebootPending)
1762 {
1763 - hr = RegKeyReadNumber(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update", L"AUState", TRUE, &dwValue);
1763 + hr = RegKeyReadNumber(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update", L"AUState", REG_KEY_DEFAULT, &dwValue);
1764 fRebootPending = SUCCEEDED(hr) && 8 == dwValue;
1765
1766 if (!fRebootPending)
1767 {
1768 - fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager", L"PendingFileRenameOperations", TRUE);
1768 + fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager", L"PendingFileRenameOperations", REG_KEY_DEFAULT);
1769
1770 if (!fRebootPending)
1771 {
1772 - fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager", L"PendingFileRenameOperations2", TRUE);
1772 + fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager", L"PendingFileRenameOperations2", REG_KEY_DEFAULT);
1773
1774 if (!fRebootPending)
1775 {
1776 - hr = RegOpen(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\FileRenameOperations", KEY_READ | KEY_WOW64_64KEY, &hk);
1776 + hr = RegOpenEx(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\FileRenameOperations", KEY_READ, REG_KEY_DEFAULT, &hk);
1777 if (SUCCEEDED(hr))
1778 {
1779 DWORD cSubKeys = 0;
src/libs/dutil/WixToolset.DUtil/butil.cpp
+138 -101
@@ -55,6 +55,7 @@ static HRESULT OpenBundleKey(
55 __in_z LPCWSTR wzBundleId,
56 __in BUNDLE_INSTALL_CONTEXT context,
57 __in_opt LPCWSTR wzSubKey,
58 + __in REG_KEY_BITNESS kbKeyBitness,
59 __inout HKEY* phKey
60 );
61 static HRESULT CopyStringToBuffer(
@@ -62,6 +63,14 @@ static HRESULT CopyStringToBuffer(
63 __in_z_opt LPWSTR wzBuffer,
64 __inout SIZE_T* pcchBuffer
65 );
66 +static HRESULT DoBundleEnumRelatedBundle(
67 + __in HKEY hkRoot,
68 + __in REG_KEY_BITNESS kbKeyBitness,
69 + __in_z LPCWSTR wzUpgradeCode,
70 + __inout PDWORD pdwStartIndex,
71 + __deref_out_z LPWSTR* psczBundleId
72 + );
73 +
74
75 DAPI_(HRESULT) BundleGetBundleInfo(
76 __in_z LPCWSTR wzBundleId,
@@ -153,113 +162,26 @@ DAPI_(HRESULT) BundleEnumRelatedBundle(
162 {
163 HRESULT hr = S_OK;
164 HKEY hkRoot = BUNDLE_INSTALL_CONTEXT_USER == context ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
156 - HKEY hkUninstall = NULL;
157 - HKEY hkBundle = NULL;
158 - LPWSTR sczUninstallSubKey = NULL;
159 - LPWSTR sczUninstallSubKeyPath = NULL;
160 - LPWSTR sczValue = NULL;
161 - DWORD dwType = 0;
162 -
163 - LPWSTR* rgsczBundleUpgradeCodes = NULL;
164 - DWORD cBundleUpgradeCodes = 0;
165 - BOOL fUpgradeCodeFound = FALSE;
165
166 if (!wzUpgradeCode || !pdwStartIndex)
167 {
168 ButilExitOnFailure(hr = E_INVALIDARG, "An invalid parameter was passed to the function.");
169 }
170
172 - hr = RegOpen(hkRoot, BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, KEY_READ, &hkUninstall);
173 - ButilExitOnFailure(hr, "Failed to open bundle uninstall key path.");
174 -
175 - for (DWORD dwIndex = *pdwStartIndex; !fUpgradeCodeFound; dwIndex++)
171 + hr = DoBundleEnumRelatedBundle(hkRoot, REG_KEY_DEFAULT, wzUpgradeCode, pdwStartIndex, psczBundleId);
172 + ButilExitOnFailure(hr, "Failed to enumerate default-bitness bundles.");
173 + if (S_FALSE == hr)
174 {
177 - hr = RegKeyEnum(hkUninstall, dwIndex, &sczUninstallSubKey);
178 - ButilExitOnFailure(hr, "Failed to enumerate bundle uninstall key path.");
179 -
180 - hr = StrAllocFormatted(&sczUninstallSubKeyPath, L"%ls\\%ls", BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, sczUninstallSubKey);
181 - ButilExitOnFailure(hr, "Failed to allocate bundle uninstall key path.");
182 -
183 - hr = RegOpen(hkRoot, sczUninstallSubKeyPath, KEY_READ, &hkBundle);
184 - ButilExitOnFailure(hr, "Failed to open uninstall key path.");
185 -
186 - // If it's a bundle, it should have a BundleUpgradeCode value of type REG_SZ (old) or REG_MULTI_SZ
187 - hr = RegGetType(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &dwType);
188 - if (FAILED(hr))
189 - {
190 - ReleaseRegKey(hkBundle);
191 - ReleaseNullStr(sczUninstallSubKey);
192 - ReleaseNullStr(sczUninstallSubKeyPath);
193 - // Not a bundle
194 - continue;
195 - }
196 -
197 - switch (dwType)
198 - {
199 - case REG_SZ:
200 - hr = RegReadString(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &sczValue);
201 - ButilExitOnFailure(hr, "Failed to read BundleUpgradeCode string property.");
202 -
203 - if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, sczValue, -1, wzUpgradeCode, -1))
204 - {
205 - *pdwStartIndex = dwIndex;
206 - fUpgradeCodeFound = TRUE;
207 - break;
208 - }
209 -
210 - ReleaseNullStr(sczValue);
211 -
212 - break;
213 - case REG_MULTI_SZ:
214 - hr = RegReadStringArray(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &rgsczBundleUpgradeCodes, &cBundleUpgradeCodes);
215 - ButilExitOnFailure(hr, "Failed to read BundleUpgradeCode multi-string property.");
216 -
217 - for (DWORD i = 0; i < cBundleUpgradeCodes; i++)
218 - {
219 - LPWSTR wzBundleUpgradeCode = rgsczBundleUpgradeCodes[i];
220 - if (wzBundleUpgradeCode && *wzBundleUpgradeCode)
221 - {
222 - if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, wzBundleUpgradeCode, -1, wzUpgradeCode, -1))
223 - {
224 - *pdwStartIndex = dwIndex;
225 - fUpgradeCodeFound = TRUE;
226 - break;
227 - }
228 - }
229 - }
230 - ReleaseNullStrArray(rgsczBundleUpgradeCodes, cBundleUpgradeCodes);
231 -
232 - break;
233 -
234 - default:
235 - ButilExitWithRootFailure(hr, E_NOTIMPL, "BundleUpgradeCode of type 0x%x not implemented.", dwType);
236 - }
237 -
238 - if (fUpgradeCodeFound)
239 - {
240 - if (psczBundleId)
241 - {
242 - *psczBundleId = sczUninstallSubKey;
243 - sczUninstallSubKey = NULL;
244 - }
245 -
246 - break;
247 - }
248 -
249 - // Cleanup before next iteration
250 - ReleaseRegKey(hkBundle);
251 - ReleaseNullStr(sczUninstallSubKey);
252 - ReleaseNullStr(sczUninstallSubKeyPath);
175 +#if defined(_WIN64)
176 + hr = DoBundleEnumRelatedBundle(hkRoot, REG_KEY_32BIT, wzUpgradeCode, pdwStartIndex, psczBundleId);
177 + ButilExitOnFailure(hr, "Failed to enumerate 32-bit bundles.");
178 +#else
179 + hr = DoBundleEnumRelatedBundle(hkRoot, REG_KEY_64BIT, wzUpgradeCode, pdwStartIndex, psczBundleId);
180 + ButilExitOnFailure(hr, "Failed to enumerate 64-bit bundles.");
181 +#endif
182 }
183
184 LExit:
256 - ReleaseStr(sczValue);
257 - ReleaseStr(sczUninstallSubKey);
258 - ReleaseStr(sczUninstallSubKeyPath);
259 - ReleaseRegKey(hkBundle);
260 - ReleaseRegKey(hkUninstall);
261 - ReleaseStrArray(rgsczBundleUpgradeCodes, cBundleUpgradeCodes);
262 -
185 return hr;
186 }
187
@@ -276,7 +198,7 @@ DAPI_(HRESULT) BundleEnumRelatedBundleFixed(
198 size_t cchValue = 0;
199
200 hr = BundleEnumRelatedBundle(wzUpgradeCode, context, pdwStartIndex, &sczValue);
279 - if (SUCCEEDED(hr) && wzBundleId)
201 + if (S_OK == hr && wzBundleId)
202 {
203 hr = ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchValue);
204 ButilExitOnRootFailure(hr, "Failed to calculate length of string.");
@@ -380,8 +302,9 @@ static HRESULT LocateAndQueryBundleValue(
302
303 *pStatus = INTERNAL_BUNDLE_STATUS_SUCCESS;
304
383 - if (FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, wzSubKey, phKey)) &&
384 - FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_USER, wzSubKey, phKey)))
305 + if (FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, wzSubKey, REG_KEY_32BIT, phKey)) &&
306 + FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, wzSubKey, REG_KEY_64BIT, phKey)) &&
307 + FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_USER, wzSubKey, REG_KEY_DEFAULT, phKey)))
308 {
309 if (E_FILENOTFOUND == hr)
310 {
@@ -413,6 +336,7 @@ static HRESULT OpenBundleKey(
336 __in_z LPCWSTR wzBundleId,
337 __in BUNDLE_INSTALL_CONTEXT context,
338 __in_opt LPCWSTR wzSubKey,
339 + __in REG_KEY_BITNESS kbKeyBitness,
340 __inout HKEY* phKey
341 )
342 {
@@ -433,7 +357,7 @@ static HRESULT OpenBundleKey(
357 }
358 ButilExitOnFailure(hr, "Failed to allocate bundle uninstall key path.");
359
436 - hr = RegOpen(hkRoot, sczKeypath, KEY_READ, phKey);
360 + hr = RegOpenEx(hkRoot, sczKeypath, KEY_READ, kbKeyBitness, phKey);
361 ButilExitOnFailure(hr, "Failed to open bundle uninstall key path.");
362
363 LExit:
@@ -472,3 +396,116 @@ static HRESULT CopyStringToBuffer(
396
397 return hr;
398 }
399 +
400 +static HRESULT DoBundleEnumRelatedBundle(
401 + __in HKEY hkRoot,
402 + __in REG_KEY_BITNESS kbKeyBitness,
403 + __in_z LPCWSTR wzUpgradeCode,
404 + __inout PDWORD pdwStartIndex,
405 + __deref_out_z LPWSTR* psczBundleId
406 +)
407 +{
408 + HRESULT hr = S_OK;
409 + BOOL fUpgradeCodeFound = FALSE;
410 + HKEY hkUninstall = NULL;
411 + HKEY hkBundle = NULL;
412 + LPWSTR sczUninstallSubKey = NULL;
413 + LPWSTR sczUninstallSubKeyPath = NULL;
414 + LPWSTR sczValue = NULL;
415 + DWORD dwType = 0;
416 + LPWSTR* rgsczBundleUpgradeCodes = NULL;
417 + DWORD cBundleUpgradeCodes = 0;
418 +
419 + hr = RegOpenEx(hkRoot, BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, KEY_READ, kbKeyBitness, &hkUninstall);
420 + ButilExitOnFailure(hr, "Failed to open bundle uninstall key path.");
421 +
422 + for (DWORD dwIndex = *pdwStartIndex; !fUpgradeCodeFound; dwIndex++)
423 + {
424 + hr = RegKeyEnum(hkUninstall, dwIndex, &sczUninstallSubKey);
425 + ButilExitOnFailure(hr, "Failed to enumerate bundle uninstall key path.");
426 +
427 + hr = StrAllocFormatted(&sczUninstallSubKeyPath, L"%ls\\%ls", BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, sczUninstallSubKey);
428 + ButilExitOnFailure(hr, "Failed to allocate bundle uninstall key path.");
429 +
430 + hr = RegOpenEx(hkRoot, sczUninstallSubKeyPath, KEY_READ, kbKeyBitness, &hkBundle);
431 + ButilExitOnFailure(hr, "Failed to open uninstall key path.");
432 +
433 + // If it's a bundle, it should have a BundleUpgradeCode value of type REG_SZ (old) or REG_MULTI_SZ
434 + hr = RegGetType(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &dwType);
435 + if (FAILED(hr))
436 + {
437 + ReleaseRegKey(hkBundle);
438 + ReleaseNullStr(sczUninstallSubKey);
439 + ReleaseNullStr(sczUninstallSubKeyPath);
440 + // Not a bundle
441 + continue;
442 + }
443 +
444 + switch (dwType)
445 + {
446 + case REG_SZ:
447 + hr = RegReadString(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &sczValue);
448 + ButilExitOnFailure(hr, "Failed to read BundleUpgradeCode string property.");
449 +
450 + if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, sczValue, -1, wzUpgradeCode, -1))
451 + {
452 + *pdwStartIndex = dwIndex;
453 + fUpgradeCodeFound = TRUE;
454 + break;
455 + }
456 +
457 + ReleaseNullStr(sczValue);
458 +
459 + break;
460 + case REG_MULTI_SZ:
461 + hr = RegReadStringArray(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &rgsczBundleUpgradeCodes, &cBundleUpgradeCodes);
462 + ButilExitOnFailure(hr, "Failed to read BundleUpgradeCode multi-string property.");
463 +
464 + for (DWORD i = 0; i < cBundleUpgradeCodes; i++)
465 + {
466 + LPWSTR wzBundleUpgradeCode = rgsczBundleUpgradeCodes[i];
467 + if (wzBundleUpgradeCode && *wzBundleUpgradeCode)
468 + {
469 + if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, wzBundleUpgradeCode, -1, wzUpgradeCode, -1))
470 + {
471 + *pdwStartIndex = dwIndex;
472 + fUpgradeCodeFound = TRUE;
473 + break;
474 + }
475 + }
476 + }
477 + ReleaseNullStrArray(rgsczBundleUpgradeCodes, cBundleUpgradeCodes);
478 +
479 + break;
480 +
481 + default:
482 + ButilExitWithRootFailure(hr, E_NOTIMPL, "BundleUpgradeCode of type 0x%x not implemented.", dwType);
483 + }
484 +
485 + if (fUpgradeCodeFound)
486 + {
487 + if (psczBundleId)
488 + {
489 + *psczBundleId = sczUninstallSubKey;
490 + sczUninstallSubKey = NULL;
491 + }
492 +
493 + break;
494 + }
495 +
496 + // Cleanup before next iteration
497 + ReleaseRegKey(hkBundle);
498 + ReleaseNullStr(sczUninstallSubKey);
499 + ReleaseNullStr(sczUninstallSubKeyPath);
500 + }
501 +
502 +LExit:
503 + ReleaseStr(sczValue);
504 + ReleaseStr(sczUninstallSubKey);
505 + ReleaseStr(sczUninstallSubKeyPath);
506 + ReleaseRegKey(hkBundle);
507 + ReleaseRegKey(hkUninstall);
508 + ReleaseStrArray(rgsczBundleUpgradeCodes, cBundleUpgradeCodes);
509 +
510 + return FAILED(hr) ? hr : fUpgradeCodeFound ? S_OK : S_FALSE;
511 +}
src/libs/dutil/WixToolset.DUtil/deputil.cpp
+3 -3
@@ -337,7 +337,7 @@ DAPI_(HRESULT) DepRegisterDependency(
337 DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey);
338
339 // Create the dependency key (or open it if it already exists).
340 - hr = RegCreateEx(hkHive, sczKey, KEY_WRITE, FALSE, NULL, &hkKey, &fCreated);
340 + hr = RegCreateEx(hkHive, sczKey, KEY_WRITE, REG_KEY_DEFAULT, FALSE, NULL, &hkKey, &fCreated);
341 DepExitOnFailure(hr, "Failed to create the dependency registry key \"%ls\".", sczKey);
342
343 // Set the id if it was provided.
@@ -417,14 +417,14 @@ DAPI_(HRESULT) DepRegisterDependent(
417 DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzDependencyProviderKey);
418
419 // Create the dependency key (or open it if it already exists).
420 - hr = RegCreateEx(hkHive, sczDependencyKey, KEY_WRITE, FALSE, NULL, &hkDependencyKey, &fCreated);
420 + hr = RegCreateEx(hkHive, sczDependencyKey, KEY_WRITE, REG_KEY_DEFAULT, FALSE, NULL, &hkDependencyKey, &fCreated);
421 DepExitOnFailure(hr, "Failed to create the dependency registry key \"%ls\".", sczDependencyKey);
422
423 // Create the subkey to register the dependent.
424 hr = StrAllocFormatted(&sczKey, L"%ls\\%ls", vsczRegistryDependents, wzProviderKey);
425 DepExitOnFailure(hr, "Failed to allocate dependent subkey \"%ls\" under dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey);
426
427 - hr = RegCreateEx(hkDependencyKey, sczKey, KEY_WRITE, FALSE, NULL, &hkKey, &fCreated);
427 + hr = RegCreateEx(hkDependencyKey, sczKey, KEY_WRITE, REG_KEY_DEFAULT, FALSE, NULL, &hkKey, &fCreated);
428 DepExitOnFailure(hr, "Failed to create the dependency subkey \"%ls\".", sczKey);
429
430 // Set the minimum version if not NULL.
src/libs/dutil/WixToolset.DUtil/inc/butil.h
+8
@@ -64,6 +64,10 @@ BundleEnumRelatedBundle - Queries the bundle installation metadata for installs
64 RETURNS:
65 E_INVALIDARG
66 An invalid parameter was passed to the function.
67 + S_OK
68 + Related bundle was found.
69 + S_FALSE
70 + Related bundle was not found.
71
72 All other returns are unexpected returns from other dutil methods.
73 ********************************************************************/
@@ -82,6 +86,10 @@ NOTE: lpBundleIdBuff is a buffer to receive the bundle GUID. This buffer must be
86 RETURNS:
87 E_INVALIDARG
88 An invalid parameter was passed to the function.
89 + S_OK
90 + Related bundle was found.
91 + S_FALSE
92 + Related bundle was not found.
93
94 All other returns are unexpected returns from other dutil methods.
95 ********************************************************************/
src/libs/dutil/WixToolset.DUtil/inc/regutil.h
+16 -3
@@ -147,6 +147,7 @@ HRESULT DAPI RegCreateEx(
147 __in HKEY hkRoot,
148 __in_z LPCWSTR wzSubKey,
149 __in DWORD dwAccess,
150 + __in REG_KEY_BITNESS kbKeyBitness,
151 __in BOOL fVolatile,
152 __in_opt SECURITY_ATTRIBUTES* pSecurityAttributes,
153 __out HKEY* phk,
@@ -162,7 +163,19 @@ HRESULT DAPI RegOpen(
163 __in_z LPCWSTR wzSubKey,
164 __in DWORD dwAccess,
165 __out HKEY* phk
165 - );
166 +);
167 +
168 +/********************************************************************
169 + RegOpenEx - opens a registry key.
170 +
171 +*********************************************************************/
172 +HRESULT DAPI RegOpenEx(
173 + __in HKEY hkRoot,
174 + __in_z LPCWSTR wzSubKey,
175 + __in DWORD dwAccess,
176 + __in REG_KEY_BITNESS kbKeyBitness,
177 + __out HKEY* phk
178 +);
179
180 /********************************************************************
181 RegDelete - deletes a registry key (and optionally it's whole tree).
@@ -379,7 +392,7 @@ HRESULT DAPI RegKeyReadNumber(
392 __in HKEY hk,
393 __in_z LPCWSTR wzSubKey,
394 __in_z_opt LPCWSTR wzName,
382 - __in BOOL f64Bit,
395 + __in REG_KEY_BITNESS kbKeyBitness,
396 __out DWORD* pdwValue
397 );
398
@@ -392,7 +405,7 @@ BOOL DAPI RegValueExists(
405 __in HKEY hk,
406 __in_z LPCWSTR wzSubKey,
407 __in_z_opt LPCWSTR wzName,
395 - __in BOOL f64Bit
408 + __in REG_KEY_BITNESS kbKeyBitness
409 );
410
411 #ifdef __cplusplus
src/libs/dutil/WixToolset.DUtil/regutil.cpp
+46 -23
@@ -32,6 +32,9 @@ static PFN_REGDELETEVALUEW vpfnRegDeleteValueW = ::RegDeleteValueW;
32 static HMODULE vhAdvApi32Dll = NULL;
33 static BOOL vfRegInitialized = FALSE;
34
35 +static REGSAM TranslateKeyBitness(
36 + __in REG_KEY_BITNESS kbKeyBitness
37 +);
38 static HRESULT WriteStringToRegistry(
39 __in HKEY hk,
40 __in_z_opt LPCWSTR wzName,
@@ -121,6 +124,7 @@ DAPI_(HRESULT) RegCreateEx(
124 __in HKEY hkRoot,
125 __in_z LPCWSTR wzSubKey,
126 __in DWORD dwAccess,
127 + __in REG_KEY_BITNESS kbKeyBitness,
128 __in BOOL fVolatile,
129 __in_opt SECURITY_ATTRIBUTES* pSecurityAttributes,
130 __out HKEY* phk,
@@ -131,7 +135,8 @@ DAPI_(HRESULT) RegCreateEx(
135 DWORD er = ERROR_SUCCESS;
136 DWORD dwDisposition;
137
134 - er = vpfnRegCreateKeyExW(hkRoot, wzSubKey, 0, NULL, fVolatile ? REG_OPTION_VOLATILE : REG_OPTION_NON_VOLATILE, dwAccess, pSecurityAttributes, phk, &dwDisposition);
138 + REGSAM samDesired = TranslateKeyBitness(kbKeyBitness);
139 + er = vpfnRegCreateKeyExW(hkRoot, wzSubKey, 0, NULL, fVolatile ? REG_OPTION_VOLATILE : REG_OPTION_NON_VOLATILE, dwAccess | samDesired, pSecurityAttributes, phk, &dwDisposition);
140 RegExitOnWin32Error(er, hr, "Failed to create registry key.");
141
142 if (pfCreated)
@@ -149,12 +154,25 @@ DAPI_(HRESULT) RegOpen(
154 __in_z LPCWSTR wzSubKey,
155 __in DWORD dwAccess,
156 __out HKEY* phk
152 - )
157 +)
158 +{
159 + return RegOpenEx(hkRoot, wzSubKey, dwAccess, REG_KEY_DEFAULT, phk);
160 +}
161 +
162 +
163 +DAPI_(HRESULT) RegOpenEx(
164 + __in HKEY hkRoot,
165 + __in_z LPCWSTR wzSubKey,
166 + __in DWORD dwAccess,
167 + __in REG_KEY_BITNESS kbKeyBitness,
168 + __out HKEY* phk
169 +)
170 {
171 HRESULT hr = S_OK;
172 DWORD er = ERROR_SUCCESS;
173
157 - er = vpfnRegOpenKeyExW(hkRoot, wzSubKey, 0, dwAccess, phk);
174 + REGSAM samDesired = TranslateKeyBitness(kbKeyBitness);
175 + er = vpfnRegOpenKeyExW(hkRoot, wzSubKey, 0, dwAccess | samDesired, phk);
176 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er))
177 {
178 ExitFunction1(hr = E_FILENOTFOUND);
@@ -178,7 +196,6 @@ DAPI_(HRESULT) RegDelete(
196 LPWSTR pszEnumeratedSubKey = NULL;
197 LPWSTR pszRecursiveSubKey = NULL;
198 HKEY hkKey = NULL;
181 - REGSAM samDesired = 0;
199
200 if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness)
201 {
@@ -186,22 +203,9 @@ DAPI_(HRESULT) RegDelete(
203 RegExitOnFailure(hr, "RegInitialize must be called first in order to RegDelete() a key with non-default bit attributes!");
204 }
205
189 - switch (kbKeyBitness)
190 - {
191 - case REG_KEY_32BIT:
192 - samDesired = KEY_WOW64_32KEY;
193 - break;
194 - case REG_KEY_64BIT:
195 - samDesired = KEY_WOW64_64KEY;
196 - break;
197 - case REG_KEY_DEFAULT:
198 - // Nothing to do
199 - break;
200 - }
201 -
206 if (fDeleteTree)
207 {
204 - hr = RegOpen(hkRoot, wzSubKey, KEY_READ | samDesired, &hkKey);
208 + hr = RegOpenEx(hkRoot, wzSubKey, KEY_READ, kbKeyBitness, &hkKey);
209 if (E_FILENOTFOUND == hr)
210 {
211 ExitFunction1(hr = S_OK);
@@ -225,6 +229,7 @@ DAPI_(HRESULT) RegDelete(
229
230 if (NULL != vpfnRegDeleteKeyExW)
231 {
232 + REGSAM samDesired = TranslateKeyBitness(kbKeyBitness);
233 er = vpfnRegDeleteKeyExW(hkRoot, wzSubKey, samDesired, 0);
234 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er))
235 {
@@ -250,7 +255,6 @@ LExit:
255 return hr;
256 }
257
253 -
258 DAPI_(HRESULT) RegKeyEnum(
259 __in HKEY hk,
260 __in DWORD dwIndex,
@@ -889,14 +893,14 @@ DAPI_(HRESULT) RegKeyReadNumber(
893 __in HKEY hk,
894 __in_z LPCWSTR wzSubKey,
895 __in_z_opt LPCWSTR wzName,
892 - __in BOOL f64Bit,
896 + __in REG_KEY_BITNESS kbKeyBitness,
897 __out DWORD* pdwValue
898 )
899 {
900 HRESULT hr = S_OK;
901 HKEY hkKey = NULL;
902
899 - hr = RegOpen(hk, wzSubKey, KEY_READ | f64Bit ? KEY_WOW64_64KEY : 0, &hkKey);
903 + hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey);
904 RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey);
905
906 hr = RegReadNumber(hkKey, wzName, pdwValue);
@@ -917,14 +921,14 @@ DAPI_(BOOL) RegValueExists(
921 __in HKEY hk,
922 __in_z LPCWSTR wzSubKey,
923 __in_z_opt LPCWSTR wzName,
920 - __in BOOL f64Bit
924 + __in REG_KEY_BITNESS kbKeyBitness
925 )
926 {
927 HRESULT hr = S_OK;
928 HKEY hkKey = NULL;
929 DWORD dwType = 0;
930
927 - hr = RegOpen(hk, wzSubKey, KEY_READ | f64Bit ? KEY_WOW64_64KEY : 0, &hkKey);
931 + hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey);
932 RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey);
933
934 hr = RegGetType(hkKey, wzName, &dwType);
@@ -936,6 +940,25 @@ LExit:
940 return SUCCEEDED(hr);
941 }
942
943 +static REGSAM TranslateKeyBitness(
944 + __in REG_KEY_BITNESS kbKeyBitness
945 + )
946 +{
947 + switch (kbKeyBitness)
948 + {
949 + case REG_KEY_32BIT:
950 + return KEY_WOW64_32KEY;
951 + break;
952 + case REG_KEY_64BIT:
953 + return KEY_WOW64_64KEY;
954 + break;
955 + case REG_KEY_DEFAULT:
956 + default:
957 + return 0;
958 + break;
959 + }
960 +}
961 +
962 static HRESULT WriteStringToRegistry(
963 __in HKEY hk,
964 __in_z_opt LPCWSTR wzName,