From a96db4a508f1d1774500ab89f2c57e581fb5a13a Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Sun, 9 Jan 2022 23:23:51 -0500 Subject: Add registry bitness to RegUtil and BUtil. Fixes https://github.com/wixtoolset/issues/issues/6669. Fixes https://github.com/wixtoolset/issues/issues/6670. --- src/burn/engine/registration.cpp | 16 +- src/libs/dutil/WixToolset.DUtil/butil.cpp | 239 +++++++++++++++----------- src/libs/dutil/WixToolset.DUtil/deputil.cpp | 6 +- src/libs/dutil/WixToolset.DUtil/inc/butil.h | 8 + src/libs/dutil/WixToolset.DUtil/inc/regutil.h | 19 +- src/libs/dutil/WixToolset.DUtil/regutil.cpp | 69 +++++--- 6 files changed, 219 insertions(+), 138 deletions(-) diff --git a/src/burn/engine/registration.cpp b/src/burn/engine/registration.cpp index ffeb39d1..a5b061eb 100644 --- a/src/burn/engine/registration.cpp +++ b/src/burn/engine/registration.cpp @@ -1742,38 +1742,38 @@ static BOOL IsRegistryRebootPending() HKEY hk = NULL; BOOL fRebootPending = FALSE; - hr = RegKeyReadNumber(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\ServerManager", L"CurrentRebootAttempts", TRUE, &dwValue); + hr = RegKeyReadNumber(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\ServerManager", L"CurrentRebootAttempts", REG_KEY_DEFAULT, &dwValue); fRebootPending = SUCCEEDED(hr) && 0 < dwValue; if (!fRebootPending) { - hr = RegKeyReadNumber(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Updates", L"UpdateExeVolatile", TRUE, &dwValue); + hr = RegKeyReadNumber(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Updates", L"UpdateExeVolatile", REG_KEY_DEFAULT, &dwValue); fRebootPending = SUCCEEDED(hr) && 0 < dwValue; if (!fRebootPending) { - fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending", NULL, TRUE); + fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending", NULL, REG_KEY_DEFAULT); if (!fRebootPending) { - fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootInProgress", NULL, TRUE); + fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootInProgress", NULL, REG_KEY_DEFAULT); if (!fRebootPending) { - hr = RegKeyReadNumber(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update", L"AUState", TRUE, &dwValue); + hr = RegKeyReadNumber(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update", L"AUState", REG_KEY_DEFAULT, &dwValue); fRebootPending = SUCCEEDED(hr) && 8 == dwValue; if (!fRebootPending) { - fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager", L"PendingFileRenameOperations", TRUE); + fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager", L"PendingFileRenameOperations", REG_KEY_DEFAULT); if (!fRebootPending) { - fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager", L"PendingFileRenameOperations2", TRUE); + fRebootPending = RegValueExists(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager", L"PendingFileRenameOperations2", REG_KEY_DEFAULT); if (!fRebootPending) { - hr = RegOpen(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\FileRenameOperations", KEY_READ | KEY_WOW64_64KEY, &hk); + hr = RegOpenEx(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\FileRenameOperations", KEY_READ, REG_KEY_DEFAULT, &hk); if (SUCCEEDED(hr)) { DWORD cSubKeys = 0; diff --git a/src/libs/dutil/WixToolset.DUtil/butil.cpp b/src/libs/dutil/WixToolset.DUtil/butil.cpp index 4c96dfc1..4262d573 100644 --- a/src/libs/dutil/WixToolset.DUtil/butil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/butil.cpp @@ -55,6 +55,7 @@ static HRESULT OpenBundleKey( __in_z LPCWSTR wzBundleId, __in BUNDLE_INSTALL_CONTEXT context, __in_opt LPCWSTR wzSubKey, + __in REG_KEY_BITNESS kbKeyBitness, __inout HKEY* phKey ); static HRESULT CopyStringToBuffer( @@ -62,6 +63,14 @@ static HRESULT CopyStringToBuffer( __in_z_opt LPWSTR wzBuffer, __inout SIZE_T* pcchBuffer ); +static HRESULT DoBundleEnumRelatedBundle( + __in HKEY hkRoot, + __in REG_KEY_BITNESS kbKeyBitness, + __in_z LPCWSTR wzUpgradeCode, + __inout PDWORD pdwStartIndex, + __deref_out_z LPWSTR* psczBundleId + ); + DAPI_(HRESULT) BundleGetBundleInfo( __in_z LPCWSTR wzBundleId, @@ -153,113 +162,26 @@ DAPI_(HRESULT) BundleEnumRelatedBundle( { HRESULT hr = S_OK; HKEY hkRoot = BUNDLE_INSTALL_CONTEXT_USER == context ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; - HKEY hkUninstall = NULL; - HKEY hkBundle = NULL; - LPWSTR sczUninstallSubKey = NULL; - LPWSTR sczUninstallSubKeyPath = NULL; - LPWSTR sczValue = NULL; - DWORD dwType = 0; - - LPWSTR* rgsczBundleUpgradeCodes = NULL; - DWORD cBundleUpgradeCodes = 0; - BOOL fUpgradeCodeFound = FALSE; if (!wzUpgradeCode || !pdwStartIndex) { ButilExitOnFailure(hr = E_INVALIDARG, "An invalid parameter was passed to the function."); } - hr = RegOpen(hkRoot, BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, KEY_READ, &hkUninstall); - ButilExitOnFailure(hr, "Failed to open bundle uninstall key path."); - - for (DWORD dwIndex = *pdwStartIndex; !fUpgradeCodeFound; dwIndex++) + hr = DoBundleEnumRelatedBundle(hkRoot, REG_KEY_DEFAULT, wzUpgradeCode, pdwStartIndex, psczBundleId); + ButilExitOnFailure(hr, "Failed to enumerate default-bitness bundles."); + if (S_FALSE == hr) { - hr = RegKeyEnum(hkUninstall, dwIndex, &sczUninstallSubKey); - ButilExitOnFailure(hr, "Failed to enumerate bundle uninstall key path."); - - hr = StrAllocFormatted(&sczUninstallSubKeyPath, L"%ls\\%ls", BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, sczUninstallSubKey); - ButilExitOnFailure(hr, "Failed to allocate bundle uninstall key path."); - - hr = RegOpen(hkRoot, sczUninstallSubKeyPath, KEY_READ, &hkBundle); - ButilExitOnFailure(hr, "Failed to open uninstall key path."); - - // If it's a bundle, it should have a BundleUpgradeCode value of type REG_SZ (old) or REG_MULTI_SZ - hr = RegGetType(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &dwType); - if (FAILED(hr)) - { - ReleaseRegKey(hkBundle); - ReleaseNullStr(sczUninstallSubKey); - ReleaseNullStr(sczUninstallSubKeyPath); - // Not a bundle - continue; - } - - switch (dwType) - { - case REG_SZ: - hr = RegReadString(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &sczValue); - ButilExitOnFailure(hr, "Failed to read BundleUpgradeCode string property."); - - if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, sczValue, -1, wzUpgradeCode, -1)) - { - *pdwStartIndex = dwIndex; - fUpgradeCodeFound = TRUE; - break; - } - - ReleaseNullStr(sczValue); - - break; - case REG_MULTI_SZ: - hr = RegReadStringArray(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &rgsczBundleUpgradeCodes, &cBundleUpgradeCodes); - ButilExitOnFailure(hr, "Failed to read BundleUpgradeCode multi-string property."); - - for (DWORD i = 0; i < cBundleUpgradeCodes; i++) - { - LPWSTR wzBundleUpgradeCode = rgsczBundleUpgradeCodes[i]; - if (wzBundleUpgradeCode && *wzBundleUpgradeCode) - { - if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, wzBundleUpgradeCode, -1, wzUpgradeCode, -1)) - { - *pdwStartIndex = dwIndex; - fUpgradeCodeFound = TRUE; - break; - } - } - } - ReleaseNullStrArray(rgsczBundleUpgradeCodes, cBundleUpgradeCodes); - - break; - - default: - ButilExitWithRootFailure(hr, E_NOTIMPL, "BundleUpgradeCode of type 0x%x not implemented.", dwType); - } - - if (fUpgradeCodeFound) - { - if (psczBundleId) - { - *psczBundleId = sczUninstallSubKey; - sczUninstallSubKey = NULL; - } - - break; - } - - // Cleanup before next iteration - ReleaseRegKey(hkBundle); - ReleaseNullStr(sczUninstallSubKey); - ReleaseNullStr(sczUninstallSubKeyPath); +#if defined(_WIN64) + hr = DoBundleEnumRelatedBundle(hkRoot, REG_KEY_32BIT, wzUpgradeCode, pdwStartIndex, psczBundleId); + ButilExitOnFailure(hr, "Failed to enumerate 32-bit bundles."); +#else + hr = DoBundleEnumRelatedBundle(hkRoot, REG_KEY_64BIT, wzUpgradeCode, pdwStartIndex, psczBundleId); + ButilExitOnFailure(hr, "Failed to enumerate 64-bit bundles."); +#endif } LExit: - ReleaseStr(sczValue); - ReleaseStr(sczUninstallSubKey); - ReleaseStr(sczUninstallSubKeyPath); - ReleaseRegKey(hkBundle); - ReleaseRegKey(hkUninstall); - ReleaseStrArray(rgsczBundleUpgradeCodes, cBundleUpgradeCodes); - return hr; } @@ -276,7 +198,7 @@ DAPI_(HRESULT) BundleEnumRelatedBundleFixed( size_t cchValue = 0; hr = BundleEnumRelatedBundle(wzUpgradeCode, context, pdwStartIndex, &sczValue); - if (SUCCEEDED(hr) && wzBundleId) + if (S_OK == hr && wzBundleId) { hr = ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchValue); ButilExitOnRootFailure(hr, "Failed to calculate length of string."); @@ -380,8 +302,9 @@ static HRESULT LocateAndQueryBundleValue( *pStatus = INTERNAL_BUNDLE_STATUS_SUCCESS; - if (FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, wzSubKey, phKey)) && - FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_USER, wzSubKey, phKey))) + if (FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, wzSubKey, REG_KEY_32BIT, phKey)) && + FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, wzSubKey, REG_KEY_64BIT, phKey)) && + FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_USER, wzSubKey, REG_KEY_DEFAULT, phKey))) { if (E_FILENOTFOUND == hr) { @@ -413,6 +336,7 @@ static HRESULT OpenBundleKey( __in_z LPCWSTR wzBundleId, __in BUNDLE_INSTALL_CONTEXT context, __in_opt LPCWSTR wzSubKey, + __in REG_KEY_BITNESS kbKeyBitness, __inout HKEY* phKey ) { @@ -433,7 +357,7 @@ static HRESULT OpenBundleKey( } ButilExitOnFailure(hr, "Failed to allocate bundle uninstall key path."); - hr = RegOpen(hkRoot, sczKeypath, KEY_READ, phKey); + hr = RegOpenEx(hkRoot, sczKeypath, KEY_READ, kbKeyBitness, phKey); ButilExitOnFailure(hr, "Failed to open bundle uninstall key path."); LExit: @@ -472,3 +396,116 @@ static HRESULT CopyStringToBuffer( return hr; } + +static HRESULT DoBundleEnumRelatedBundle( + __in HKEY hkRoot, + __in REG_KEY_BITNESS kbKeyBitness, + __in_z LPCWSTR wzUpgradeCode, + __inout PDWORD pdwStartIndex, + __deref_out_z LPWSTR* psczBundleId +) +{ + HRESULT hr = S_OK; + BOOL fUpgradeCodeFound = FALSE; + HKEY hkUninstall = NULL; + HKEY hkBundle = NULL; + LPWSTR sczUninstallSubKey = NULL; + LPWSTR sczUninstallSubKeyPath = NULL; + LPWSTR sczValue = NULL; + DWORD dwType = 0; + LPWSTR* rgsczBundleUpgradeCodes = NULL; + DWORD cBundleUpgradeCodes = 0; + + hr = RegOpenEx(hkRoot, BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, KEY_READ, kbKeyBitness, &hkUninstall); + ButilExitOnFailure(hr, "Failed to open bundle uninstall key path."); + + for (DWORD dwIndex = *pdwStartIndex; !fUpgradeCodeFound; dwIndex++) + { + hr = RegKeyEnum(hkUninstall, dwIndex, &sczUninstallSubKey); + ButilExitOnFailure(hr, "Failed to enumerate bundle uninstall key path."); + + hr = StrAllocFormatted(&sczUninstallSubKeyPath, L"%ls\\%ls", BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, sczUninstallSubKey); + ButilExitOnFailure(hr, "Failed to allocate bundle uninstall key path."); + + hr = RegOpenEx(hkRoot, sczUninstallSubKeyPath, KEY_READ, kbKeyBitness, &hkBundle); + ButilExitOnFailure(hr, "Failed to open uninstall key path."); + + // If it's a bundle, it should have a BundleUpgradeCode value of type REG_SZ (old) or REG_MULTI_SZ + hr = RegGetType(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &dwType); + if (FAILED(hr)) + { + ReleaseRegKey(hkBundle); + ReleaseNullStr(sczUninstallSubKey); + ReleaseNullStr(sczUninstallSubKeyPath); + // Not a bundle + continue; + } + + switch (dwType) + { + case REG_SZ: + hr = RegReadString(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &sczValue); + ButilExitOnFailure(hr, "Failed to read BundleUpgradeCode string property."); + + if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, sczValue, -1, wzUpgradeCode, -1)) + { + *pdwStartIndex = dwIndex; + fUpgradeCodeFound = TRUE; + break; + } + + ReleaseNullStr(sczValue); + + break; + case REG_MULTI_SZ: + hr = RegReadStringArray(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &rgsczBundleUpgradeCodes, &cBundleUpgradeCodes); + ButilExitOnFailure(hr, "Failed to read BundleUpgradeCode multi-string property."); + + for (DWORD i = 0; i < cBundleUpgradeCodes; i++) + { + LPWSTR wzBundleUpgradeCode = rgsczBundleUpgradeCodes[i]; + if (wzBundleUpgradeCode && *wzBundleUpgradeCode) + { + if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, wzBundleUpgradeCode, -1, wzUpgradeCode, -1)) + { + *pdwStartIndex = dwIndex; + fUpgradeCodeFound = TRUE; + break; + } + } + } + ReleaseNullStrArray(rgsczBundleUpgradeCodes, cBundleUpgradeCodes); + + break; + + default: + ButilExitWithRootFailure(hr, E_NOTIMPL, "BundleUpgradeCode of type 0x%x not implemented.", dwType); + } + + if (fUpgradeCodeFound) + { + if (psczBundleId) + { + *psczBundleId = sczUninstallSubKey; + sczUninstallSubKey = NULL; + } + + break; + } + + // Cleanup before next iteration + ReleaseRegKey(hkBundle); + ReleaseNullStr(sczUninstallSubKey); + ReleaseNullStr(sczUninstallSubKeyPath); + } + +LExit: + ReleaseStr(sczValue); + ReleaseStr(sczUninstallSubKey); + ReleaseStr(sczUninstallSubKeyPath); + ReleaseRegKey(hkBundle); + ReleaseRegKey(hkUninstall); + ReleaseStrArray(rgsczBundleUpgradeCodes, cBundleUpgradeCodes); + + return FAILED(hr) ? hr : fUpgradeCodeFound ? S_OK : S_FALSE; +} diff --git a/src/libs/dutil/WixToolset.DUtil/deputil.cpp b/src/libs/dutil/WixToolset.DUtil/deputil.cpp index 2e6d6a6c..754365e9 100644 --- a/src/libs/dutil/WixToolset.DUtil/deputil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/deputil.cpp @@ -337,7 +337,7 @@ DAPI_(HRESULT) DepRegisterDependency( DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzProviderKey); // Create the dependency key (or open it if it already exists). - hr = RegCreateEx(hkHive, sczKey, KEY_WRITE, FALSE, NULL, &hkKey, &fCreated); + hr = RegCreateEx(hkHive, sczKey, KEY_WRITE, REG_KEY_DEFAULT, FALSE, NULL, &hkKey, &fCreated); DepExitOnFailure(hr, "Failed to create the dependency registry key \"%ls\".", sczKey); // Set the id if it was provided. @@ -417,14 +417,14 @@ DAPI_(HRESULT) DepRegisterDependent( DepExitOnFailure(hr, "Failed to allocate the registry key for dependency \"%ls\".", wzDependencyProviderKey); // Create the dependency key (or open it if it already exists). - hr = RegCreateEx(hkHive, sczDependencyKey, KEY_WRITE, FALSE, NULL, &hkDependencyKey, &fCreated); + hr = RegCreateEx(hkHive, sczDependencyKey, KEY_WRITE, REG_KEY_DEFAULT, FALSE, NULL, &hkDependencyKey, &fCreated); DepExitOnFailure(hr, "Failed to create the dependency registry key \"%ls\".", sczDependencyKey); // Create the subkey to register the dependent. hr = StrAllocFormatted(&sczKey, L"%ls\\%ls", vsczRegistryDependents, wzProviderKey); DepExitOnFailure(hr, "Failed to allocate dependent subkey \"%ls\" under dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey); - hr = RegCreateEx(hkDependencyKey, sczKey, KEY_WRITE, FALSE, NULL, &hkKey, &fCreated); + hr = RegCreateEx(hkDependencyKey, sczKey, KEY_WRITE, REG_KEY_DEFAULT, FALSE, NULL, &hkKey, &fCreated); DepExitOnFailure(hr, "Failed to create the dependency subkey \"%ls\".", sczKey); // Set the minimum version if not NULL. diff --git a/src/libs/dutil/WixToolset.DUtil/inc/butil.h b/src/libs/dutil/WixToolset.DUtil/inc/butil.h index 0405be8b..3b316e66 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/butil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/butil.h @@ -64,6 +64,10 @@ BundleEnumRelatedBundle - Queries the bundle installation metadata for installs RETURNS: E_INVALIDARG An invalid parameter was passed to the function. + S_OK + Related bundle was found. + S_FALSE + Related bundle was not found. All other returns are unexpected returns from other dutil methods. ********************************************************************/ @@ -82,6 +86,10 @@ NOTE: lpBundleIdBuff is a buffer to receive the bundle GUID. This buffer must be RETURNS: E_INVALIDARG An invalid parameter was passed to the function. + S_OK + Related bundle was found. + S_FALSE + Related bundle was not found. All other returns are unexpected returns from other dutil methods. ********************************************************************/ diff --git a/src/libs/dutil/WixToolset.DUtil/inc/regutil.h b/src/libs/dutil/WixToolset.DUtil/inc/regutil.h index ae47f75e..db8e0c5c 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/regutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/regutil.h @@ -147,6 +147,7 @@ HRESULT DAPI RegCreateEx( __in HKEY hkRoot, __in_z LPCWSTR wzSubKey, __in DWORD dwAccess, + __in REG_KEY_BITNESS kbKeyBitness, __in BOOL fVolatile, __in_opt SECURITY_ATTRIBUTES* pSecurityAttributes, __out HKEY* phk, @@ -162,7 +163,19 @@ HRESULT DAPI RegOpen( __in_z LPCWSTR wzSubKey, __in DWORD dwAccess, __out HKEY* phk - ); +); + +/******************************************************************** + RegOpenEx - opens a registry key. + +*********************************************************************/ +HRESULT DAPI RegOpenEx( + __in HKEY hkRoot, + __in_z LPCWSTR wzSubKey, + __in DWORD dwAccess, + __in REG_KEY_BITNESS kbKeyBitness, + __out HKEY* phk +); /******************************************************************** RegDelete - deletes a registry key (and optionally it's whole tree). @@ -379,7 +392,7 @@ HRESULT DAPI RegKeyReadNumber( __in HKEY hk, __in_z LPCWSTR wzSubKey, __in_z_opt LPCWSTR wzName, - __in BOOL f64Bit, + __in REG_KEY_BITNESS kbKeyBitness, __out DWORD* pdwValue ); @@ -392,7 +405,7 @@ BOOL DAPI RegValueExists( __in HKEY hk, __in_z LPCWSTR wzSubKey, __in_z_opt LPCWSTR wzName, - __in BOOL f64Bit + __in REG_KEY_BITNESS kbKeyBitness ); #ifdef __cplusplus diff --git a/src/libs/dutil/WixToolset.DUtil/regutil.cpp b/src/libs/dutil/WixToolset.DUtil/regutil.cpp index 57093f97..f4719466 100644 --- a/src/libs/dutil/WixToolset.DUtil/regutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/regutil.cpp @@ -32,6 +32,9 @@ static PFN_REGDELETEVALUEW vpfnRegDeleteValueW = ::RegDeleteValueW; static HMODULE vhAdvApi32Dll = NULL; static BOOL vfRegInitialized = FALSE; +static REGSAM TranslateKeyBitness( + __in REG_KEY_BITNESS kbKeyBitness +); static HRESULT WriteStringToRegistry( __in HKEY hk, __in_z_opt LPCWSTR wzName, @@ -121,6 +124,7 @@ DAPI_(HRESULT) RegCreateEx( __in HKEY hkRoot, __in_z LPCWSTR wzSubKey, __in DWORD dwAccess, + __in REG_KEY_BITNESS kbKeyBitness, __in BOOL fVolatile, __in_opt SECURITY_ATTRIBUTES* pSecurityAttributes, __out HKEY* phk, @@ -131,7 +135,8 @@ DAPI_(HRESULT) RegCreateEx( DWORD er = ERROR_SUCCESS; DWORD dwDisposition; - er = vpfnRegCreateKeyExW(hkRoot, wzSubKey, 0, NULL, fVolatile ? REG_OPTION_VOLATILE : REG_OPTION_NON_VOLATILE, dwAccess, pSecurityAttributes, phk, &dwDisposition); + REGSAM samDesired = TranslateKeyBitness(kbKeyBitness); + er = vpfnRegCreateKeyExW(hkRoot, wzSubKey, 0, NULL, fVolatile ? REG_OPTION_VOLATILE : REG_OPTION_NON_VOLATILE, dwAccess | samDesired, pSecurityAttributes, phk, &dwDisposition); RegExitOnWin32Error(er, hr, "Failed to create registry key."); if (pfCreated) @@ -149,12 +154,25 @@ DAPI_(HRESULT) RegOpen( __in_z LPCWSTR wzSubKey, __in DWORD dwAccess, __out HKEY* phk - ) +) +{ + return RegOpenEx(hkRoot, wzSubKey, dwAccess, REG_KEY_DEFAULT, phk); +} + + +DAPI_(HRESULT) RegOpenEx( + __in HKEY hkRoot, + __in_z LPCWSTR wzSubKey, + __in DWORD dwAccess, + __in REG_KEY_BITNESS kbKeyBitness, + __out HKEY* phk +) { HRESULT hr = S_OK; DWORD er = ERROR_SUCCESS; - er = vpfnRegOpenKeyExW(hkRoot, wzSubKey, 0, dwAccess, phk); + REGSAM samDesired = TranslateKeyBitness(kbKeyBitness); + er = vpfnRegOpenKeyExW(hkRoot, wzSubKey, 0, dwAccess | samDesired, phk); if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) { ExitFunction1(hr = E_FILENOTFOUND); @@ -178,7 +196,6 @@ DAPI_(HRESULT) RegDelete( LPWSTR pszEnumeratedSubKey = NULL; LPWSTR pszRecursiveSubKey = NULL; HKEY hkKey = NULL; - REGSAM samDesired = 0; if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness) { @@ -186,22 +203,9 @@ DAPI_(HRESULT) RegDelete( RegExitOnFailure(hr, "RegInitialize must be called first in order to RegDelete() a key with non-default bit attributes!"); } - switch (kbKeyBitness) - { - case REG_KEY_32BIT: - samDesired = KEY_WOW64_32KEY; - break; - case REG_KEY_64BIT: - samDesired = KEY_WOW64_64KEY; - break; - case REG_KEY_DEFAULT: - // Nothing to do - break; - } - if (fDeleteTree) { - hr = RegOpen(hkRoot, wzSubKey, KEY_READ | samDesired, &hkKey); + hr = RegOpenEx(hkRoot, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); if (E_FILENOTFOUND == hr) { ExitFunction1(hr = S_OK); @@ -225,6 +229,7 @@ DAPI_(HRESULT) RegDelete( if (NULL != vpfnRegDeleteKeyExW) { + REGSAM samDesired = TranslateKeyBitness(kbKeyBitness); er = vpfnRegDeleteKeyExW(hkRoot, wzSubKey, samDesired, 0); if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) { @@ -250,7 +255,6 @@ LExit: return hr; } - DAPI_(HRESULT) RegKeyEnum( __in HKEY hk, __in DWORD dwIndex, @@ -889,14 +893,14 @@ DAPI_(HRESULT) RegKeyReadNumber( __in HKEY hk, __in_z LPCWSTR wzSubKey, __in_z_opt LPCWSTR wzName, - __in BOOL f64Bit, + __in REG_KEY_BITNESS kbKeyBitness, __out DWORD* pdwValue ) { HRESULT hr = S_OK; HKEY hkKey = NULL; - hr = RegOpen(hk, wzSubKey, KEY_READ | f64Bit ? KEY_WOW64_64KEY : 0, &hkKey); + hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey); hr = RegReadNumber(hkKey, wzName, pdwValue); @@ -917,14 +921,14 @@ DAPI_(BOOL) RegValueExists( __in HKEY hk, __in_z LPCWSTR wzSubKey, __in_z_opt LPCWSTR wzName, - __in BOOL f64Bit + __in REG_KEY_BITNESS kbKeyBitness ) { HRESULT hr = S_OK; HKEY hkKey = NULL; DWORD dwType = 0; - hr = RegOpen(hk, wzSubKey, KEY_READ | f64Bit ? KEY_WOW64_64KEY : 0, &hkKey); + hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey); hr = RegGetType(hkKey, wzName, &dwType); @@ -936,6 +940,25 @@ LExit: return SUCCEEDED(hr); } +static REGSAM TranslateKeyBitness( + __in REG_KEY_BITNESS kbKeyBitness + ) +{ + switch (kbKeyBitness) + { + case REG_KEY_32BIT: + return KEY_WOW64_32KEY; + break; + case REG_KEY_64BIT: + return KEY_WOW64_64KEY; + break; + case REG_KEY_DEFAULT: + default: + return 0; + break; + } +} + static HRESULT WriteStringToRegistry( __in HKEY hk, __in_z_opt LPCWSTR wzName, -- cgit v1.2.3-55-g6feb