Author: hbelusca Date: Sun Nov 27 20:39:10 2016 New Revision: 73401
URL: http://svn.reactos.org/svn/reactos?rev=73401&view=rev Log: [SERVICES] - The new ScmDeleteServiceKey (r73400) and the already existing ScmDeleteRegKey are the same functions: remove the old ScmDeleteRegKey and use ScmDeleteServiceKey instead AND rename ScmDeleteServiceKey to ScmDeleteRegKey (as it can be used generically within services.exe). - Call RegDeleteKeyW for the subkey after we have closed its opened handle.
Modified: trunk/reactos/base/system/services/config.c trunk/reactos/base/system/services/database.c trunk/reactos/base/system/services/rpcserver.c trunk/reactos/base/system/services/services.h
Modified: trunk/reactos/base/system/services/config.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/config... ============================================================================== --- trunk/reactos/base/system/services/config.c [iso-8859-1] (original) +++ trunk/reactos/base/system/services/config.c [iso-8859-1] Sun Nov 27 20:39:10 2016 @@ -617,22 +617,22 @@
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 @@ 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; }
Modified: trunk/reactos/base/system/services/database.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/databa... ============================================================================== --- trunk/reactos/base/system/services/database.c [iso-8859-1] (original) +++ trunk/reactos/base/system/services/database.c [iso-8859-1] Sun Nov 27 20:39:10 2016 @@ -735,55 +735,6 @@ }
return dwError; -} - - -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; }
Modified: trunk/reactos/base/system/services/rpcserver.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/rpcser... ============================================================================== --- trunk/reactos/base/system/services/rpcserver.c [iso-8859-1] (original) +++ trunk/reactos/base/system/services/rpcserver.c [iso-8859-1] Sun Nov 27 20:39:10 2016 @@ -1026,8 +1026,8 @@ it is now safe to delete the service */
/* Delete the Service Key */ - dwError = ScmDeleteServiceKey(hServicesKey, - lpService->lpServiceName); + dwError = ScmDeleteRegKey(hServicesKey, + lpService->lpServiceName);
RegCloseKey(hServicesKey);
Modified: trunk/reactos/base/system/services/services.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/servic... ============================================================================== --- trunk/reactos/base/system/services/services.h [iso-8859-1] (original) +++ trunk/reactos/base/system/services/services.h [iso-8859-1] Sun Nov 27 20:39:10 2016 @@ -143,9 +143,9 @@ _Out_ PSECURITY_DESCRIPTOR *ppSecurityDescriptor);
DWORD -ScmDeleteServiceKey( - _In_ HKEY hServicesKey, - _In_ PCWSTR pszServiceName); +ScmDeleteRegKey( + _In_ HKEY hKey, + _In_ PCWSTR pszSubKey);
/* controlset.c */