mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 01:15:09 +00:00
[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. svn path=/trunk/; revision=73401
This commit is contained in:
parent
a96ca3a4c1
commit
49284f4696
4 changed files with 21 additions and 66 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
Loading…
Reference in a new issue