Made ServiceCurrent key volatile
authorGregor Brunmar <gbrunmar.ros@gmail.com>
Mon, 5 Nov 2007 17:41:20 +0000 (17:41 +0000)
committerGregor Brunmar <gbrunmar.ros@gmail.com>
Mon, 5 Nov 2007 17:41:20 +0000 (17:41 +0000)
svn path=/trunk/; revision=30190

reactos/base/system/services/database.c

index fb1cc6a..13471d2 100644 (file)
@@ -698,6 +698,8 @@ ScmStartUserModeService(PSERVICE Service,
     NTSTATUS Status;
     DWORD dwError = ERROR_SUCCESS;
     WCHAR NtControlPipeName[MAX_PATH + 1];
+    HKEY hServiceCurrentKey = INVALID_HANDLE_VALUE;
+    DWORD KeyDisposition;
 
     RtlInitUnicodeString(&ImagePath, NULL);
 
@@ -727,39 +729,44 @@ ScmStartUserModeService(PSERVICE Service,
     DPRINT("Type: %lx\n", Type);
 
     /* Get the service number */
-    RtlZeroMemory(&QueryTable,
-                  sizeof(QueryTable));
-
-    QueryTable[0].Name = L"";
-    QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
-    QueryTable[0].EntryContext = &ServiceCurrent;
-
-    Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
-                                    L"ServiceCurrent",
-                                    QueryTable,
-                                    NULL,
-                                    NULL);
+    /* TODO: Create registry entry with correct write access */
+    Status = RegCreateKeyExW(HKEY_LOCAL_MACHINE,
+                            L"SYSTEM\\CurrentControlSet\\Control\\ServiceCurrent", 0, NULL,
+                            REG_OPTION_VOLATILE,
+                            KEY_WRITE | KEY_READ,
+                            NULL,
+                            &hServiceCurrentKey,
+                            &KeyDisposition);
 
-    if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
+    if (ERROR_SUCCESS != Status)
     {
-        /* TODO: Create registry entry with correct write access */
-    }
-    else if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status);
-        return RtlNtStatusToDosError(Status);
+        DPRINT1("RegCreateKeyEx() failed with status %u\n", Status);
+        return Status;
     }
-    else
+
+    if (REG_OPENED_EXISTING_KEY == KeyDisposition)
     {
+        DWORD KeySize = sizeof(ServiceCurrent);
+        Status = RegQueryValueExW(hServiceCurrentKey, L"", 0, NULL, (BYTE*)&ServiceCurrent, &KeySize);
+
+        if (ERROR_SUCCESS != Status)
+        {
+            RegCloseKey(hServiceCurrentKey);
+            DPRINT1("RegQueryValueEx() failed with status %u\n", Status);
+            return Status;
+        }
+
         ServiceCurrent++;
     }
 
-    Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL, L"ServiceCurrent", L"", REG_DWORD, &ServiceCurrent, sizeof(ServiceCurrent));
+    Status = RegSetValueExW(hServiceCurrentKey, L"", 0, REG_DWORD, (BYTE*)&ServiceCurrent, sizeof(ServiceCurrent));
 
-    if (!NT_SUCCESS(Status))
+    RegCloseKey(hServiceCurrentKey);
+
+    if (ERROR_SUCCESS != Status)
     {
-        DPRINT1("RtlWriteRegistryValue() failed (Status %lx)\n", Status);
-        return RtlNtStatusToDosError(Status);
+        DPRINT1("RegSetValueExW() failed (Status %lx)\n", Status);
+        return Status;
     }
 
     /* Create '\\.\pipe\net\NtControlPipeXXX' instance */