2 * SHLWAPI registry functions
12 #include "debugtools.h"
14 #include "wine/unicode.h"
16 DEFAULT_DEBUG_CHANNEL(shell);
18 static const char *lpszContentTypeA = "Content Type";
19 static const WCHAR lpszContentTypeW[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
21 /*************************************************************************
22 * SHRegGetUSValueA [SHLWAPI.@]
24 * Gets a user-specific registry value
26 LONG WINAPI SHRegGetUSValueA(
34 DWORD wDefaultDataSize)
36 FIXME("(%p),stub!\n", pSubKey);
37 return ERROR_SUCCESS; /* return success */
40 /*************************************************************************
41 * SHRegGetUSValueW [SHLWAPI.@]
43 * Gets a user-specific registry value
45 LONG WINAPI SHRegGetUSValueW(
53 DWORD wDefaultDataSize)
55 FIXME("(%p),stub!\n", pSubKey);
56 return ERROR_SUCCESS; /* return success */
59 /*************************************************************************
60 * SHRegOpenUSKeyA [SHLWAPI.@]
62 * Opens a user-specific registry key
64 LONG WINAPI SHRegOpenUSKeyA(
72 return ERROR_SUCCESS; /* return success */
75 /*************************************************************************
76 * SHRegOpenUSKeyW [SHLWAPI.@]
78 * Openss a user-specific registry key
80 LONG WINAPI SHRegOpenUSKeyW(
88 return ERROR_SUCCESS; /* return success */
91 /*************************************************************************
92 * SHRegGetBoolUSValueA [SHLWAPI.@]
94 BOOL WINAPI SHRegGetBoolUSValueA(
100 FIXME("%s %s\n", pszSubKey,pszValue);
104 /*************************************************************************
105 * SHRegGetBoolUSValueW [SHLWAPI.@]
107 BOOL WINAPI SHRegGetBoolUSValueW(
113 FIXME("%s %s\n", debugstr_w(pszSubKey),debugstr_w(pszValue));
117 /*************************************************************************
118 * SHRegQueryUSValueA [SHLWAPI.@]
120 LONG WINAPI SHRegQueryUSValueA(
121 HKEY hUSKey, /* [in] FIXME: HUSKEY */
128 DWORD dwDefaultDataSize)
130 FIXME("%s stub\n",pszValue);
134 /*************************************************************************
135 * SHRegQueryUSValueW [SHLWAPI.@]
137 LONG WINAPI SHRegQueryUSValueW(
138 HKEY hUSKey, /* [in] FIXME: HUSKEY */
145 DWORD dwDefaultDataSize)
147 FIXME("%s stub\n",pszValue);
151 /*************************************************************************
152 * SHRegGetPathA [SHLWAPI.@]
154 DWORD WINAPI SHRegGetPathA(
161 FIXME("%s %s\n", pcszSubKey, pcszValue);
165 /*************************************************************************
166 * SHRegGetPathW [SHLWAPI.@]
168 DWORD WINAPI SHRegGetPathW(
175 FIXME("%s %s\n", debugstr_w(pcszSubKey), debugstr_w(pcszValue));
179 /*************************************************************************
180 * SHGetValueA [SHLWAPI.@]
182 * Gets a value from the registry
184 DWORD WINAPI SHGetValueA(
195 TRACE("(%s %s)\n", pSubKey, pValue);
197 if((res = RegOpenKeyA(hkey, pSubKey, &hSubKey))) return res;
198 res = RegQueryValueExA(hSubKey, pValue, 0, pwType, pvData, pbData);
199 RegCloseKey( hSubKey );
204 /*************************************************************************
205 * SHGetValueW [SHLWAPI.@]
207 * Gets a value from the registry
209 DWORD WINAPI SHGetValueW(
220 TRACE("(%s %s)\n", debugstr_w(pSubKey), debugstr_w(pValue));
222 if((res = RegOpenKeyW(hkey, pSubKey, &hSubKey))) return res;
223 res = RegQueryValueExW(hSubKey, pValue, 0, pwType, pvData, pbData);
224 RegCloseKey( hSubKey );
229 /*************************************************************************
230 * SHSetValueA [SHLWAPI.@]
232 HRESULT WINAPI SHSetValueA(
243 hres = RegCreateKeyA(hkey,pszSubKey,&subkey);
246 hres = RegSetValueExA(subkey,pszValue,0,dwType,pvData,cbData);
251 /*************************************************************************
252 * SHSetValueW [SHLWAPI.@]
254 HRESULT WINAPI SHSetValueW(
265 hres = RegCreateKeyW(hkey,pszSubKey,&subkey);
268 hres = RegSetValueExW(subkey,pszValue,0,dwType,pvData,cbData);
273 /*************************************************************************
274 * SHQueryValueExA [SHLWAPI.@]
277 HRESULT WINAPI SHQueryValueExA(
285 TRACE("0x%04x %s %p %p %p %p\n", hkey, lpValueName, lpReserved, lpType, lpData, lpcbData);
286 return RegQueryValueExA (hkey, lpValueName, lpReserved, lpType, lpData, lpcbData);
290 /*************************************************************************
291 * SHQueryValueExW [SHLWAPI.@]
294 * if the datatype REG_EXPAND_SZ then expand the string and change
295 * *pdwType to REG_SZ.
297 HRESULT WINAPI SHQueryValueExW (
305 WARN("0x%04x %s %p %p %p %p semi-stub\n",
306 hkey, debugstr_w(pszValue), pdwReserved, pdwType, pvData, pcbData);
307 return RegQueryValueExW ( hkey, pszValue, pdwReserved, pdwType, pvData, pcbData);
310 /*************************************************************************
311 * SHDeleteKeyA [SHLWAPI.@]
313 * It appears this function is made available to account for the differences
314 * between the Win9x and WinNT/2k RegDeleteKeyA functions.
316 * According to docs, Win9x RegDeleteKeyA will delete all subkeys, whereas
317 * WinNt/2k will only delete the key if empty.
319 HRESULT WINAPI SHDeleteKeyA(
323 DWORD r, dwKeyCount, dwSize, i, dwMaxSubkeyLen;
327 TRACE("hkey=0x%08x, %s\n", hKey, debugstr_a(lpszSubKey));
330 r = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
331 if(r != ERROR_SUCCESS)
334 /* find how many subkeys there are */
337 r = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, &dwKeyCount,
338 &dwMaxSubkeyLen, NULL, NULL, NULL, NULL, NULL, NULL);
339 if(r != ERROR_SUCCESS)
341 RegCloseKey(hSubKey);
345 /* alloc memory for the longest string terminating 0 */
347 lpszName = HeapAlloc(GetProcessHeap(), 0, dwMaxSubkeyLen*sizeof(CHAR));
350 RegCloseKey(hSubKey);
351 return ERROR_NOT_ENOUGH_MEMORY;
354 /* recursively delete all the subkeys */
355 for(i=0; i<dwKeyCount; i++)
357 dwSize = dwMaxSubkeyLen;
358 r = RegEnumKeyExA(hSubKey, i, lpszName, &dwSize, NULL, NULL, NULL, NULL);
359 if(r != ERROR_SUCCESS)
361 r = SHDeleteKeyA(hSubKey, lpszName);
362 if(r != ERROR_SUCCESS)
366 HeapFree(GetProcessHeap(), 0, lpszName);
368 RegCloseKey(hSubKey);
370 if(r == ERROR_SUCCESS)
371 r = RegDeleteKeyA(hKey, lpszSubKey);
376 /*************************************************************************
377 * SHDeleteKeyW [SHLWAPI.@]
379 * It appears this function is made available to account for the differences
380 * between the Win9x and WinNT/2k RegDeleteKeyA functions.
382 * According to docs, Win9x RegDeleteKeyA will delete all subkeys, whereas
383 * WinNt/2k will only delete the key if empty.
385 HRESULT WINAPI SHDeleteKeyW(
389 FIXME("hkey=0x%08x, %s\n", hkey, debugstr_w(pszSubKey));
393 /*************************************************************************
394 * SHDeleteValueA [SHLWAPI.@]
396 * Function opens the key, get/set/delete the value, then close the key.
398 HRESULT WINAPI SHDeleteValueA(HKEY hkey, LPCSTR pszSubKey, LPCSTR pszValue) {
402 hres = RegOpenKeyA(hkey,pszSubKey,&subkey);
405 hres = RegDeleteValueA(subkey,pszValue);
410 /*************************************************************************
411 * SHDeleteValueW [SHLWAPI.@]
413 * Function opens the key, get/set/delete the value, then close the key.
415 HRESULT WINAPI SHDeleteValueW(HKEY hkey, LPCWSTR pszSubKey, LPCWSTR pszValue) {
419 hres = RegOpenKeyW(hkey,pszSubKey,&subkey);
422 hres = RegDeleteValueW(subkey,pszValue);
427 /*************************************************************************
428 * SHDeleteEmptyKeyA [SHLWAPI.@]
430 * It appears this function is made available to account for the differences
431 * between the Win9x and WinNT/2k RegDeleteKeyA functions.
433 * According to docs, Win9x RegDeleteKeyA will delete all subkeys, whereas
434 * WinNt/2k will only delete the key if empty.
436 DWORD WINAPI SHDeleteEmptyKeyA(HKEY hKey, LPCSTR lpszSubKey)
441 TRACE("hkey=0x%08x, %s\n", hKey, debugstr_a(lpszSubKey));
444 r = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
445 if(r != ERROR_SUCCESS)
449 r = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, &dwKeyCount,
450 NULL, NULL, NULL, NULL, NULL, NULL, NULL);
451 if(r != ERROR_SUCCESS)
454 RegCloseKey(hSubKey);
457 return ERROR_KEY_HAS_CHILDREN;
459 r = RegDeleteKeyA(hKey, lpszSubKey);
464 /*************************************************************************
465 * SHDeleteEmptyKeyW [SHLWAPI.@]
467 * It appears this function is made available to account for the differences
468 * between the Win9x and WinNT/2k RegDeleteKeyA functions.
470 * According to docs, Win9x RegDeleteKeyA will delete all subkeys, whereas
471 * WinNt/2k will only delete the key if empty.
473 DWORD WINAPI SHDeleteEmptyKeyW(HKEY hKey, LPCWSTR lpszSubKey)
475 FIXME("hkey=0x%08x, %s\n", hKey, debugstr_w(lpszSubKey));
479 /*************************************************************************
482 * Wrapper for SHGetValueA in case machine is in safe mode.
484 DWORD WINAPI SHLWAPI_205(HKEY hkey, LPCSTR pSubKey, LPCSTR pValue,
485 LPDWORD pwType, LPVOID pvData, LPDWORD pbData)
487 if (GetSystemMetrics(SM_CLEANBOOT))
488 return ERROR_INVALID_FUNCTION;
489 return SHGetValueA(hkey, pSubKey, pValue, pwType, pvData, pbData);
492 /*************************************************************************
495 * Unicode version of SHLWAPI_205.
497 DWORD WINAPI SHLWAPI_206(HKEY hkey, LPCWSTR pSubKey, LPCWSTR pValue,
498 LPDWORD pwType, LPVOID pvData, LPDWORD pbData)
500 if (GetSystemMetrics(SM_CLEANBOOT))
501 return ERROR_INVALID_FUNCTION;
502 return SHGetValueW(hkey, pSubKey, pValue, pwType, pvData, pbData);
505 /*************************************************************************
509 BOOL WINAPI SHLWAPI_320(LPCSTR lpszSubKey, LPCSTR lpszValue)
511 DWORD dwLen = strlen(lpszValue);
512 HRESULT ret = SHSetValueA(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeA,
513 REG_SZ, lpszValue, dwLen);
514 return ret ? FALSE : TRUE;
517 /*************************************************************************
520 * Unicode version of SHLWAPI_320.
522 BOOL WINAPI SHLWAPI_321(LPCWSTR lpszSubKey, LPCWSTR lpszValue)
524 DWORD dwLen = strlenW(lpszValue);
525 HRESULT ret = SHSetValueW(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeW,
526 REG_SZ, lpszValue, dwLen);
527 return ret ? FALSE : TRUE;
530 /*************************************************************************
534 BOOL WINAPI SHLWAPI_322(LPCSTR lpszSubKey)
536 HRESULT ret = SHDeleteValueA(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeA);
537 return ret ? FALSE : TRUE;
540 /*************************************************************************
543 * Unicode version of SHLWAPI_322.
545 BOOL WINAPI SHLWAPI_323(LPCWSTR lpszSubKey)
547 HRESULT ret = SHDeleteValueW(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeW);
548 return ret ? FALSE : TRUE;