📄 reg.c
字号:
}
return dwRet;
}
/*************************************************************************
* SHDeleteEmptyKeyW [SHLWAPI.@]
*
* See SHDeleteEmptyKeyA.
*/
DWORD WINAPI SHDeleteEmptyKeyW(HKEY hKey, LPCWSTR lpszSubKey)
{
DWORD dwRet, dwKeyCount = 0;
HKEY hSubKey = 0;
TRACE("(hkey=%p, %s)\n", hKey, debugstr_w(lpszSubKey));
dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
if(!dwRet)
{
dwRet = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &dwKeyCount,
NULL, NULL, NULL, NULL, NULL, NULL, NULL);
RegCloseKey(hSubKey);
if(!dwRet)
{
if (!dwKeyCount)
dwRet = RegDeleteKeyW(hKey, lpszSubKey);
else
dwRet = ERROR_KEY_HAS_CHILDREN;
}
}
return dwRet;
}
/*************************************************************************
* SHDeleteOrphanKeyA [SHLWAPI.@]
*
* Delete a registry key with no sub keys or values.
*
* PARAMS
* hKey [I] Handle to registry key
* lpszSubKey [I] Name of sub key to possibly delete
*
* RETURNS
* Success: ERROR_SUCCESS. The key has been deleted if it was an orphan.
* Failure: An error from RegOpenKeyExA(), RegQueryValueExA(), or RegDeleteKeyA().
*/
DWORD WINAPI SHDeleteOrphanKeyA(HKEY hKey, LPCSTR lpszSubKey)
{
HKEY hSubKey;
DWORD dwKeyCount = 0, dwValueCount = 0, dwRet;
TRACE("(hkey=%p,%s)\n", hKey, debugstr_a(lpszSubKey));
dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
if(!dwRet)
{
/* Get subkey and value count */
dwRet = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, &dwKeyCount,
NULL, NULL, &dwValueCount, NULL, NULL, NULL, NULL);
if(!dwRet && !dwKeyCount && !dwValueCount)
{
dwRet = RegDeleteKeyA(hKey, lpszSubKey);
}
RegCloseKey(hSubKey);
}
return dwRet;
}
/*************************************************************************
* SHDeleteOrphanKeyW [SHLWAPI.@]
*
* See SHDeleteOrphanKeyA.
*/
DWORD WINAPI SHDeleteOrphanKeyW(HKEY hKey, LPCWSTR lpszSubKey)
{
HKEY hSubKey;
DWORD dwKeyCount = 0, dwValueCount = 0, dwRet;
TRACE("(hkey=%p,%s)\n", hKey, debugstr_w(lpszSubKey));
dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
if(!dwRet)
{
/* Get subkey and value count */
dwRet = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &dwKeyCount,
NULL, NULL, &dwValueCount, NULL, NULL, NULL, NULL);
if(!dwRet && !dwKeyCount && !dwValueCount)
{
dwRet = RegDeleteKeyW(hKey, lpszSubKey);
}
RegCloseKey(hSubKey);
}
return dwRet;
}
/*************************************************************************
* SHDeleteValueA [SHLWAPI.@]
*
* Delete a value from the registry.
*
* PARAMS
* hKey [I] Handle to registry key
* lpszSubKey [I] Name of sub key containing value to delete
* lpszValue [I] Name of value to delete
*
* RETURNS
* Success: ERROR_SUCCESS. The value is deleted.
* Failure: An error code from RegOpenKeyExA() or RegDeleteValueA().
*/
DWORD WINAPI SHDeleteValueA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue)
{
DWORD dwRet;
HKEY hSubKey;
TRACE("(hkey=%p,%s,%s)\n", hKey, debugstr_a(lpszSubKey), debugstr_a(lpszValue));
dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_SET_VALUE, &hSubKey);
if (!dwRet)
{
dwRet = RegDeleteValueA(hSubKey, lpszValue);
RegCloseKey(hSubKey);
}
return dwRet;
}
/*************************************************************************
* SHDeleteValueW [SHLWAPI.@]
*
* See SHDeleteValueA.
*/
DWORD WINAPI SHDeleteValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue)
{
DWORD dwRet;
HKEY hSubKey;
TRACE("(hkey=%p,%s,%s)\n", hKey, debugstr_w(lpszSubKey), debugstr_w(lpszValue));
dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_SET_VALUE, &hSubKey);
if (!dwRet)
{
dwRet = RegDeleteValueW(hSubKey, lpszValue);
RegCloseKey(hSubKey);
}
return dwRet;
}
/*************************************************************************
* SHEnumKeyExA [SHLWAPI.@]
*
* Enumerate sub keys in a registry key.
*
* PARAMS
* hKey [I] Handle to registry key
* dwIndex [I] Index of key to enumerate
* lpszSubKey [O] Pointer updated with the subkey name
* pwLen [O] Pointer updated with the subkey length
*
* RETURNS
* Success: ERROR_SUCCESS. lpszSubKey and pwLen are updated.
* Failure: An error code from RegEnumKeyExA().
*/
LONG WINAPI SHEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpszSubKey,
LPDWORD pwLen)
{
TRACE("(hkey=%p,%d,%s,%p)\n", hKey, dwIndex, debugstr_a(lpszSubKey), pwLen);
return RegEnumKeyExA(hKey, dwIndex, lpszSubKey, pwLen, NULL, NULL, NULL, NULL);
}
/*************************************************************************
* SHEnumKeyExW [SHLWAPI.@]
*
* See SHEnumKeyExA.
*/
LONG WINAPI SHEnumKeyExW(HKEY hKey, DWORD dwIndex, LPWSTR lpszSubKey,
LPDWORD pwLen)
{
TRACE("(hkey=%p,%d,%s,%p)\n", hKey, dwIndex, debugstr_w(lpszSubKey), pwLen);
return RegEnumKeyExW(hKey, dwIndex, lpszSubKey, pwLen, NULL, NULL, NULL, NULL);
}
/*************************************************************************
* SHEnumValueA [SHLWAPI.@]
*
* Enumerate values in a registry key.
*
* PARAMS
* hKey [I] Handle to registry key
* dwIndex [I] Index of key to enumerate
* lpszValue [O] Pointer updated with the values name
* pwLen [O] Pointer updated with the values length
* pwType [O] Pointer updated with the values type
* pvData [O] Pointer updated with the values data
* pcbData [O] Pointer updated with the values size
*
* RETURNS
* Success: ERROR_SUCCESS. Output parameters are updated.
* Failure: An error code from RegEnumValueA().
*/
LONG WINAPI SHEnumValueA(HKEY hKey, DWORD dwIndex, LPSTR lpszValue,
LPDWORD pwLen, LPDWORD pwType,
LPVOID pvData, LPDWORD pcbData)
{
TRACE("(hkey=%p,%d,%s,%p,%p,%p,%p)\n", hKey, dwIndex,
debugstr_a(lpszValue), pwLen, pwType, pvData, pcbData);
return RegEnumValueA(hKey, dwIndex, lpszValue, pwLen, NULL,
pwType, pvData, pcbData);
}
/*************************************************************************
* SHEnumValueW [SHLWAPI.@]
*
* See SHEnumValueA.
*/
LONG WINAPI SHEnumValueW(HKEY hKey, DWORD dwIndex, LPWSTR lpszValue,
LPDWORD pwLen, LPDWORD pwType,
LPVOID pvData, LPDWORD pcbData)
{
TRACE("(hkey=%p,%d,%s,%p,%p,%p,%p)\n", hKey, dwIndex,
debugstr_w(lpszValue), pwLen, pwType, pvData, pcbData);
return RegEnumValueW(hKey, dwIndex, lpszValue, pwLen, NULL,
pwType, pvData, pcbData);
}
/*************************************************************************
* @ [SHLWAPI.205]
*
* Get a value from the registry.
*
* PARAMS
* hKey [I] Handle to registry key
* pSubKey [I] Name of sub key containing value to get
* pValue [I] Name of value to get
* pwType [O] Destination for the values type
* pvData [O] Destination for the values data
* pbData [O] Destination for the values size
*
* RETURNS
* Success: ERROR_SUCCESS. Output parameters contain the details read.
* Failure: An error code from RegOpenKeyExA() or SHQueryValueExA(),
* or ERROR_INVALID_FUNCTION in the machine is in safe mode.
*/
DWORD WINAPI SHGetValueGoodBootA(HKEY hkey, LPCSTR pSubKey, LPCSTR pValue,
LPDWORD pwType, LPVOID pvData, LPDWORD pbData)
{
if (GetSystemMetrics(SM_CLEANBOOT))
return ERROR_INVALID_FUNCTION;
return SHGetValueA(hkey, pSubKey, pValue, pwType, pvData, pbData);
}
/*************************************************************************
* @ [SHLWAPI.206]
*
* Unicode version of SHGetValueGoodBootW.
*/
DWORD WINAPI SHGetValueGoodBootW(HKEY hkey, LPCWSTR pSubKey, LPCWSTR pValue,
LPDWORD pwType, LPVOID pvData, LPDWORD pbData)
{
if (GetSystemMetrics(SM_CLEANBOOT))
return ERROR_INVALID_FUNCTION;
return SHGetValueW(hkey, pSubKey, pValue, pwType, pvData, pbData);
}
/*************************************************************************
* @ [SHLWAPI.320]
*
* Set a MIME content type in the registry.
*
* PARAMS
* lpszSubKey [I] Name of key under HKEY_CLASSES_ROOT.
* lpszValue [I] Value to set
*
* RETURNS
* Success: TRUE
* Failure: FALSE
*/
BOOL WINAPI RegisterMIMETypeForExtensionA(LPCSTR lpszSubKey, LPCSTR lpszValue)
{
DWORD dwRet;
if (!lpszValue)
{
WARN("Invalid lpszValue would crash under Win32!\n");
return FALSE;
}
dwRet = SHSetValueA(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeA,
REG_SZ, lpszValue, strlen(lpszValue));
return dwRet ? FALSE : TRUE;
}
/*************************************************************************
* @ [SHLWAPI.321]
*
* Unicode version of RegisterMIMETypeForExtensionA.
*/
BOOL WINAPI RegisterMIMETypeForExtensionW(LPCWSTR lpszSubKey, LPCWSTR lpszValue)
{
DWORD dwRet;
if (!lpszValue)
{
WARN("Invalid lpszValue would crash under Win32!\n");
return FALSE;
}
dwRet = SHSetValueW(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeW,
REG_SZ, lpszValue, strlenW(lpszValue));
return dwRet ? FALSE : TRUE;
}
/*************************************************************************
* @ [SHLWAPI.322]
*
* Delete a MIME content type from the registry.
*
* PARAMS
* lpszSubKey [I] Name of sub key
*
* RETURNS
* Success: TRUE
* Failure: FALSE
*/
BOOL WINAPI UnregisterMIMETypeForExtensionA(LPCSTR lpszSubKey)
{
HRESULT ret = SHDeleteValueA(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeA);
return ret ? FALSE : TRUE;
}
/*************************************************************************
* @ [SHLWAPI.323]
*
* Unicode version of UnregisterMIMETypeForExtensionA.
*/
BOOL WINAPI UnregisterMIMETypeForExtensionW(LPCWSTR lpszSubKey)
{
HRESULT ret = SHDeleteValueW(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeW);
return ret ? FALSE : TRUE;
}
/*************************************************************************
* @ [SHLWAPI.328]
*
* Get the registry path to a MIME content key.
*
* PARAMS
* lpszType [I] Content type to get the path for
* lpszBuffer [O] Destination for path
* dwLen [I] Length of lpszBuffer
*
* RETURNS
* Success: TRUE. lpszBuffer contains the full path.
* Failure: FALSE.
*
* NOTES
* The base path for the key is "MIME\Database\Content Type\"
*/
BOOL WINAPI GetMIMETypeSubKeyA(LPCSTR lpszType, LPSTR lpszBuffer, DWORD dwLen)
{
TRACE("(%s,%p,%d)\n", debugstr_a(lpszType), lpszBuffer, dwLen);
if (dwLen > dwLenMimeDbContent && lpszType && lpszBuffer)
{
size_t dwStrLen = strlen(lpszType);
if (dwStrLen < dwLen - dwLenMimeDbContent)
{
memcpy(lpszBuffer, szMimeDbContentA, dwLenMimeDbContent);
memcpy(lpszBuffer + dwLenMimeDbContent, lpszType, dwStrLen + 1);
return TRUE;
}
}
return FALSE;
}
/*************************************************************************
* @ [SHLWAPI.329]
*
* Unicode version of GetMIMETypeSubKeyA.
*/
BOOL WINAPI GetMIMETypeSubKeyW(LPCWSTR lpszType, LPWSTR lpszBuffer, DWORD dwLen)
{
TRACE("(%s,%p,%d)\n", debugstr_w(lpszType), lpszBuffer, dwLen);
if (dwLen > dwLenMimeDbContent && lpszType && lpszBuffer)
{
DWORD dwStrLen = strlenW(lpszType);
if (dwStrLen < dwLen - dwLenMimeDbContent)
{
memcpy(lpszBuffer, szMimeDbContentW, dwLenMimeDbContent * sizeof(WCHAR));
memcpy(lpszBuffer + dwLenMimeDbContent, lpszType, (dwStrLen + 1) * s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -