aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/regutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/regutil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/regutil.cpp69
1 files changed, 46 insertions, 23 deletions
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;
32static HMODULE vhAdvApi32Dll = NULL; 32static HMODULE vhAdvApi32Dll = NULL;
33static BOOL vfRegInitialized = FALSE; 33static BOOL vfRegInitialized = FALSE;
34 34
35static REGSAM TranslateKeyBitness(
36 __in REG_KEY_BITNESS kbKeyBitness
37);
35static HRESULT WriteStringToRegistry( 38static HRESULT WriteStringToRegistry(
36 __in HKEY hk, 39 __in HKEY hk,
37 __in_z_opt LPCWSTR wzName, 40 __in_z_opt LPCWSTR wzName,
@@ -121,6 +124,7 @@ DAPI_(HRESULT) RegCreateEx(
121 __in HKEY hkRoot, 124 __in HKEY hkRoot,
122 __in_z LPCWSTR wzSubKey, 125 __in_z LPCWSTR wzSubKey,
123 __in DWORD dwAccess, 126 __in DWORD dwAccess,
127 __in REG_KEY_BITNESS kbKeyBitness,
124 __in BOOL fVolatile, 128 __in BOOL fVolatile,
125 __in_opt SECURITY_ATTRIBUTES* pSecurityAttributes, 129 __in_opt SECURITY_ATTRIBUTES* pSecurityAttributes,
126 __out HKEY* phk, 130 __out HKEY* phk,
@@ -131,7 +135,8 @@ DAPI_(HRESULT) RegCreateEx(
131 DWORD er = ERROR_SUCCESS; 135 DWORD er = ERROR_SUCCESS;
132 DWORD dwDisposition; 136 DWORD dwDisposition;
133 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);
135 RegExitOnWin32Error(er, hr, "Failed to create registry key."); 140 RegExitOnWin32Error(er, hr, "Failed to create registry key.");
136 141
137 if (pfCreated) 142 if (pfCreated)
@@ -149,12 +154,25 @@ DAPI_(HRESULT) RegOpen(
149 __in_z LPCWSTR wzSubKey, 154 __in_z LPCWSTR wzSubKey,
150 __in DWORD dwAccess, 155 __in DWORD dwAccess,
151 __out HKEY* phk 156 __out HKEY* phk
152 ) 157)
158{
159 return RegOpenEx(hkRoot, wzSubKey, dwAccess, REG_KEY_DEFAULT, phk);
160}
161
162
163DAPI_(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)
153{ 170{
154 HRESULT hr = S_OK; 171 HRESULT hr = S_OK;
155 DWORD er = ERROR_SUCCESS; 172 DWORD er = ERROR_SUCCESS;
156 173
157 er = vpfnRegOpenKeyExW(hkRoot, wzSubKey, 0, dwAccess, phk); 174 REGSAM samDesired = TranslateKeyBitness(kbKeyBitness);
175 er = vpfnRegOpenKeyExW(hkRoot, wzSubKey, 0, dwAccess | samDesired, phk);
158 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) 176 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er))
159 { 177 {
160 ExitFunction1(hr = E_FILENOTFOUND); 178 ExitFunction1(hr = E_FILENOTFOUND);
@@ -178,7 +196,6 @@ DAPI_(HRESULT) RegDelete(
178 LPWSTR pszEnumeratedSubKey = NULL; 196 LPWSTR pszEnumeratedSubKey = NULL;
179 LPWSTR pszRecursiveSubKey = NULL; 197 LPWSTR pszRecursiveSubKey = NULL;
180 HKEY hkKey = NULL; 198 HKEY hkKey = NULL;
181 REGSAM samDesired = 0;
182 199
183 if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness) 200 if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness)
184 { 201 {
@@ -186,22 +203,9 @@ DAPI_(HRESULT) RegDelete(
186 RegExitOnFailure(hr, "RegInitialize must be called first in order to RegDelete() a key with non-default bit attributes!"); 203 RegExitOnFailure(hr, "RegInitialize must be called first in order to RegDelete() a key with non-default bit attributes!");
187 } 204 }
188 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
202 if (fDeleteTree) 206 if (fDeleteTree)
203 { 207 {
204 hr = RegOpen(hkRoot, wzSubKey, KEY_READ | samDesired, &hkKey); 208 hr = RegOpenEx(hkRoot, wzSubKey, KEY_READ, kbKeyBitness, &hkKey);
205 if (E_FILENOTFOUND == hr) 209 if (E_FILENOTFOUND == hr)
206 { 210 {
207 ExitFunction1(hr = S_OK); 211 ExitFunction1(hr = S_OK);
@@ -225,6 +229,7 @@ DAPI_(HRESULT) RegDelete(
225 229
226 if (NULL != vpfnRegDeleteKeyExW) 230 if (NULL != vpfnRegDeleteKeyExW)
227 { 231 {
232 REGSAM samDesired = TranslateKeyBitness(kbKeyBitness);
228 er = vpfnRegDeleteKeyExW(hkRoot, wzSubKey, samDesired, 0); 233 er = vpfnRegDeleteKeyExW(hkRoot, wzSubKey, samDesired, 0);
229 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) 234 if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er))
230 { 235 {
@@ -250,7 +255,6 @@ LExit:
250 return hr; 255 return hr;
251} 256}
252 257
253
254DAPI_(HRESULT) RegKeyEnum( 258DAPI_(HRESULT) RegKeyEnum(
255 __in HKEY hk, 259 __in HKEY hk,
256 __in DWORD dwIndex, 260 __in DWORD dwIndex,
@@ -889,14 +893,14 @@ DAPI_(HRESULT) RegKeyReadNumber(
889 __in HKEY hk, 893 __in HKEY hk,
890 __in_z LPCWSTR wzSubKey, 894 __in_z LPCWSTR wzSubKey,
891 __in_z_opt LPCWSTR wzName, 895 __in_z_opt LPCWSTR wzName,
892 __in BOOL f64Bit, 896 __in REG_KEY_BITNESS kbKeyBitness,
893 __out DWORD* pdwValue 897 __out DWORD* pdwValue
894 ) 898 )
895{ 899{
896 HRESULT hr = S_OK; 900 HRESULT hr = S_OK;
897 HKEY hkKey = NULL; 901 HKEY hkKey = NULL;
898 902
899 hr = RegOpen(hk, wzSubKey, KEY_READ | f64Bit ? KEY_WOW64_64KEY : 0, &hkKey); 903 hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey);
900 RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey); 904 RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey);
901 905
902 hr = RegReadNumber(hkKey, wzName, pdwValue); 906 hr = RegReadNumber(hkKey, wzName, pdwValue);
@@ -917,14 +921,14 @@ DAPI_(BOOL) RegValueExists(
917 __in HKEY hk, 921 __in HKEY hk,
918 __in_z LPCWSTR wzSubKey, 922 __in_z LPCWSTR wzSubKey,
919 __in_z_opt LPCWSTR wzName, 923 __in_z_opt LPCWSTR wzName,
920 __in BOOL f64Bit 924 __in REG_KEY_BITNESS kbKeyBitness
921 ) 925 )
922{ 926{
923 HRESULT hr = S_OK; 927 HRESULT hr = S_OK;
924 HKEY hkKey = NULL; 928 HKEY hkKey = NULL;
925 DWORD dwType = 0; 929 DWORD dwType = 0;
926 930
927 hr = RegOpen(hk, wzSubKey, KEY_READ | f64Bit ? KEY_WOW64_64KEY : 0, &hkKey); 931 hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey);
928 RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey); 932 RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey);
929 933
930 hr = RegGetType(hkKey, wzName, &dwType); 934 hr = RegGetType(hkKey, wzName, &dwType);
@@ -936,6 +940,25 @@ LExit:
936 return SUCCEEDED(hr); 940 return SUCCEEDED(hr);
937} 941}
938 942
943static 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
939static HRESULT WriteStringToRegistry( 962static HRESULT WriteStringToRegistry(
940 __in HKEY hk, 963 __in HKEY hk,
941 __in_z_opt LPCWSTR wzName, 964 __in_z_opt LPCWSTR wzName,