Author: ekohl
Date: Sun Nov 27 20:12:39 2016
New Revision: 73400
URL:
http://svn.reactos.org/svn/reactos?rev=73400&view=rev
Log:
[SERVICES]
Delete service registry keys recursively.
Modified:
trunk/reactos/base/system/services/config.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/confi…
==============================================================================
--- 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:12:39 2016
@@ -615,4 +615,62 @@
return dwError;
}
+
+DWORD
+ScmDeleteServiceKey(
+ _In_ HKEY hServicesKey,
+ _In_ PCWSTR pszServiceName)
+{
+ DWORD dwMaxSubkeyLen, dwMaxValueLen;
+ DWORD dwMaxLen, dwSize;
+ PWSTR pszName = NULL;
+ HKEY hServiceKey;
+ DWORD dwError;
+
+ dwError = RegOpenKeyExW(hServicesKey, pszServiceName, 0, KEY_READ,
&hServiceKey);
+ if (dwError != ERROR_SUCCESS)
+ return dwError;
+
+ /* Get maximum length of key and value names */
+ dwError = RegQueryInfoKeyW(hServiceKey, NULL, NULL, NULL, NULL,
+ &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL,
NULL, NULL);
+ if (dwError != ERROR_SUCCESS)
+ goto done;
+
+ dwMaxSubkeyLen++;
+ dwMaxValueLen++;
+ dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
+
+ /* Allocate the name buffer */
+ pszName = HeapAlloc(GetProcessHeap(), 0, dwMaxLen * sizeof(WCHAR));
+ if (pszName == NULL)
+ {
+ dwError = ERROR_NOT_ENOUGH_MEMORY;
+ goto done;
+ }
+
+ /* Recursively delete all the subkeys */
+ while (TRUE)
+ {
+ dwSize = dwMaxLen;
+ if (RegEnumKeyExW(hServiceKey, 0, pszName, &dwSize,
+ NULL, NULL, NULL, NULL))
+ break;
+
+ dwError = ScmDeleteServiceKey(hServiceKey, pszName);
+ if (dwError != ERROR_SUCCESS)
+ goto done;
+ }
+
+ dwError = RegDeleteKeyW(hServicesKey, pszServiceName);
+
+done:
+ if (pszName != NULL)
+ HeapFree(GetProcessHeap(), 0, pszName);
+
+ RegCloseKey(hServiceKey);
+
+ return dwError;
+}
+
/* EOF */
Modified: trunk/reactos/base/system/services/rpcserver.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/rpcse…
==============================================================================
--- 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:12:39 2016
@@ -1026,8 +1026,8 @@
it is now safe to delete the service */
/* Delete the Service Key */
- dwError = RegDeleteKeyW(hServicesKey,
- lpService->lpServiceName);
+ dwError = ScmDeleteServiceKey(hServicesKey,
+ lpService->lpServiceName);
RegCloseKey(hServicesKey);
@@ -1443,7 +1443,7 @@
{
PSERVICE_HANDLE hSvc;
PSERVICE lpService;
- ULONG DesiredAccess = 0;
+ ACCESS_MASK DesiredAccess = 0;
HANDLE hToken = NULL;
HKEY hServiceKey = NULL;
BOOL bDatabaseLocked = FALSE;
Modified: trunk/reactos/base/system/services/services.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/system/services/servi…
==============================================================================
--- 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:12:39 2016
@@ -142,6 +142,10 @@
_In_ HKEY hServiceKey,
_Out_ PSECURITY_DESCRIPTOR *ppSecurityDescriptor);
+DWORD
+ScmDeleteServiceKey(
+ _In_ HKEY hServicesKey,
+ _In_ PCWSTR pszServiceName);
/* controlset.c */