Browse Source

Clean up Parameters properly.

If create_parameters() failed to write Application, AppParameters or
AppDirectory it would try to clean up by deleting the Parameters key.
The method used to do so was flawed.  It would attempt to delete the key
defined by the NSSM_REGISTRY macro but that macro contains a printf
control string and is not suitable for standalone use.
Iain Patterson 9 năm trước cách đây
mục cha
commit
e072e7ea67
1 tập tin đã thay đổi với 7 bổ sung3 xóa
  1. 7 3
      registry.cpp

+ 7 - 3
registry.cpp

@@ -32,19 +32,23 @@ int create_parameters(nssm_service_t *service, bool editing) {
   HKEY key = open_registry(service->name, KEY_WRITE);
   if (! key) return 1;
 
+  /* Remember parameters in case we need to delete them. */
+  TCHAR registry[KEY_LENGTH];
+  int ret = service_registry_path(service->name, true, 0, registry, _countof(registry));
+
   /* Try to create the parameters */
   if (set_expand_string(key, NSSM_REG_EXE, service->exe)) {
-    RegDeleteKey(HKEY_LOCAL_MACHINE, NSSM_REGISTRY);
+    if (ret > 0) RegDeleteKey(HKEY_LOCAL_MACHINE, registry);
     RegCloseKey(key);
     return 2;
   }
   if (set_expand_string(key, NSSM_REG_FLAGS, service->flags)) {
-    RegDeleteKey(HKEY_LOCAL_MACHINE, NSSM_REGISTRY);
+    if (ret > 0) RegDeleteKey(HKEY_LOCAL_MACHINE, registry);
     RegCloseKey(key);
     return 3;
   }
   if (set_expand_string(key, NSSM_REG_DIR, service->dir)) {
-    RegDeleteKey(HKEY_LOCAL_MACHINE, NSSM_REGISTRY);
+    if (ret > 0) RegDeleteKey(HKEY_LOCAL_MACHINE, registry);
     RegCloseKey(key);
     return 4;
   }