From a963edca41666f28d9fc62c29431779619a34eb2 Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Fri, 5 May 2017 19:28:15 +0400 Subject: [PATCH 1/2] Add a registry key deletion test that fails with WoW64 --- tests/config/regconf.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/config/regconf.cpp b/tests/config/regconf.cpp index 37763583c6..0521a18353 100644 --- a/tests/config/regconf.cpp +++ b/tests/config/regconf.cpp @@ -35,6 +35,7 @@ public: private: CPPUNIT_TEST_SUITE( RegConfigTestCase ); CPPUNIT_TEST( ReadWrite ); + CPPUNIT_TEST( DeleteRegistryKeyFromRedirectedView ); CPPUNIT_TEST_SUITE_END(); void ReadWrite(); @@ -80,5 +81,25 @@ void RegConfigTestCase::ReadWrite() delete config; } +void RegConfigTestCase::DeleteRegistryKeyFromRedirectedView() +{ + if ( !wxIsPlatform64Bit() ) + { + // Test needs WoW64. + return; + } + + // Test inside a key that's known to be redirected and is in HKCU so that + // admin rights are not required (unlike with HKLM). + wxRegKey key(wxRegKey::HKCU, "SOFTWARE\\Classes\\CLSID\\wxWidgetsTestKey", + sizeof(void *) == 4 + ? wxRegKey::WOW64ViewMode_64 + : wxRegKey::WOW64ViewMode_32); + + CPPUNIT_ASSERT( key.Create() ); + CPPUNIT_ASSERT( key.DeleteSelf() ); + CPPUNIT_ASSERT( !key.Exists() ); +} + #endif // wxUSE_CONFIG && wxUSE_REGKEY From 8d2ed7bdf073a7d37e7f7441fe17401402b51e3f Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Fri, 5 May 2017 19:30:19 +0400 Subject: [PATCH 2/2] Fix deletion of registry keys from alternate registry view Since being able to access the 64 bit registry from 32 bit code and vice versa (a5c468483d) the updated code in wxRegKey::DeleteKey hasn't worked properly for keys that are redirected. It is for example not possible from 32 bit code to delete keys from the 64 bit view of (parts of) HKLM/SOFTWARE/ . And in 64 bit code it's not possible to delete keys from the 32 bit view of HKLM/SOFTWARE/ which is at HKLM/SOFTWARE/WOW6432Node/ . Fix by trying to call the correct DLL function (RegDeleteKeyExW or RegDeleteKeyExA), instead of non-existing RegDeleteKeyEx. --- src/msw/registry.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index aef56fdec2..63d2e1bf70 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -757,11 +757,10 @@ bool wxRegKey::DeleteSelf() #if wxUSE_DYNLIB_CLASS wxDynamicLibrary dllAdvapi32(wxT("advapi32")); // Minimum supported OS for RegDeleteKeyEx: Vista, XP Pro x64, Win Server 2008, Win Server 2003 SP1 - if(dllAdvapi32.HasSymbol(wxT("RegDeleteKeyEx"))) + typedef LONG (WINAPI *RegDeleteKeyEx_t)(HKEY, LPCTSTR, REGSAM, DWORD); + RegDeleteKeyEx_t wxDL_INIT_FUNC_AW(pfn, RegDeleteKeyEx, dllAdvapi32); + if (pfnRegDeleteKeyEx) { - typedef LONG (WINAPI *RegDeleteKeyEx_t)(HKEY, LPCTSTR, REGSAM, DWORD); - wxDYNLIB_FUNCTION(RegDeleteKeyEx_t, RegDeleteKeyEx, dllAdvapi32); - m_dwLastError = (*pfnRegDeleteKeyEx)((HKEY) m_hRootKey, m_strKey.t_str(), GetMSWViewFlags(m_viewMode), 0); // This parameter is reserved and must be zero.