diff --git a/reactos/base/system/services/config.c b/reactos/base/system/services/config.c index 6e376178e81..c101a9f3ee9 100644 --- a/reactos/base/system/services/config.c +++ b/reactos/base/system/services/config.c @@ -617,22 +617,22 @@ done: DWORD -ScmDeleteServiceKey( - _In_ HKEY hServicesKey, - _In_ PCWSTR pszServiceName) +ScmDeleteRegKey( + _In_ HKEY hKey, + _In_ PCWSTR pszSubKey) { DWORD dwMaxSubkeyLen, dwMaxValueLen; DWORD dwMaxLen, dwSize; PWSTR pszName = NULL; - HKEY hServiceKey; + HKEY hSubKey; DWORD dwError; - dwError = RegOpenKeyExW(hServicesKey, pszServiceName, 0, KEY_READ, &hServiceKey); + dwError = RegOpenKeyExW(hKey, pszSubKey, 0, KEY_READ, &hSubKey); if (dwError != ERROR_SUCCESS) return dwError; /* Get maximum length of key and value names */ - dwError = RegQueryInfoKeyW(hServiceKey, NULL, NULL, NULL, NULL, + dwError = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL, &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL); if (dwError != ERROR_SUCCESS) goto done; @@ -653,22 +653,26 @@ ScmDeleteServiceKey( while (TRUE) { dwSize = dwMaxLen; - if (RegEnumKeyExW(hServiceKey, 0, pszName, &dwSize, - NULL, NULL, NULL, NULL)) + if (RegEnumKeyExW(hSubKey, 0, pszName, &dwSize, + NULL, NULL, NULL, NULL) != ERROR_SUCCESS) + { break; + } - dwError = ScmDeleteServiceKey(hServiceKey, pszName); + dwError = ScmDeleteServiceKey(hSubKey, pszName); if (dwError != ERROR_SUCCESS) goto done; } - dwError = RegDeleteKeyW(hServicesKey, pszServiceName); - done: if (pszName != NULL) HeapFree(GetProcessHeap(), 0, pszName); - RegCloseKey(hServiceKey); + RegCloseKey(hSubKey); + + /* Finally delete the key */ + if (dwError == ERROR_SUCCESS) + dwError = RegDeleteKeyW(hKey, pszSubKey); return dwError; } diff --git a/reactos/base/system/services/database.c b/reactos/base/system/services/database.c index 7036efe0217..6a54248f1a3 100644 --- a/reactos/base/system/services/database.c +++ b/reactos/base/system/services/database.c @@ -738,55 +738,6 @@ done: } -DWORD -ScmDeleteRegKey(HKEY hKey, LPCWSTR lpszSubKey) -{ - DWORD dwRet, dwMaxSubkeyLen = 0, dwSize; - WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf; - HKEY hSubKey = 0; - - dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey); - if (!dwRet) - { - /* Find the maximum subkey length so that we can allocate a buffer */ - dwRet = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL, - &dwMaxSubkeyLen, NULL, NULL, NULL, NULL, NULL, NULL); - if (!dwRet) - { - dwMaxSubkeyLen++; - if (dwMaxSubkeyLen > sizeof(szNameBuf) / sizeof(WCHAR)) - { - /* Name too big: alloc a buffer for it */ - lpszName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwMaxSubkeyLen * sizeof(WCHAR)); - } - - if (!lpszName) - dwRet = ERROR_NOT_ENOUGH_MEMORY; - else - { - while (dwRet == ERROR_SUCCESS) - { - dwSize = dwMaxSubkeyLen; - dwRet = RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL, NULL, NULL, NULL); - if (dwRet == ERROR_SUCCESS || dwRet == ERROR_MORE_DATA) - dwRet = ScmDeleteRegKey(hSubKey, lpszName); - } - if (dwRet == ERROR_NO_MORE_ITEMS) - dwRet = ERROR_SUCCESS; - - if (lpszName != szNameBuf) - HeapFree(GetProcessHeap(), 0, lpszName); /* Free buffer if allocated */ - } - } - - RegCloseKey(hSubKey); - if (!dwRet) - dwRet = RegDeleteKeyW(hKey, lpszSubKey); - } - return dwRet; -} - - VOID ScmDeleteMarkedServices(VOID) { diff --git a/reactos/base/system/services/rpcserver.c b/reactos/base/system/services/rpcserver.c index cfce13b4366..8ec07d55c65 100644 --- a/reactos/base/system/services/rpcserver.c +++ b/reactos/base/system/services/rpcserver.c @@ -1026,8 +1026,8 @@ DWORD RCloseServiceHandle( it is now safe to delete the service */ /* Delete the Service Key */ - dwError = ScmDeleteServiceKey(hServicesKey, - lpService->lpServiceName); + dwError = ScmDeleteRegKey(hServicesKey, + lpService->lpServiceName); RegCloseKey(hServicesKey); diff --git a/reactos/base/system/services/services.h b/reactos/base/system/services/services.h index 8f4aadbfe6c..83ac0b0cd90 100644 --- a/reactos/base/system/services/services.h +++ b/reactos/base/system/services/services.h @@ -143,9 +143,9 @@ ScmReadSecurityDescriptor( _Out_ PSECURITY_DESCRIPTOR *ppSecurityDescriptor); DWORD -ScmDeleteServiceKey( - _In_ HKEY hServicesKey, - _In_ PCWSTR pszServiceName); +ScmDeleteRegKey( + _In_ HKEY hKey, + _In_ PCWSTR pszSubKey); /* controlset.c */