X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=registry.cpp;h=e49993309075edab42ad15ddddd57b4a2c74f1af;hb=095331018c46d251f6db151572bb1c2e76e911fa;hp=5953f8a9f867d09ec6a489e292be085c64483796;hpb=66861c12e7d515f4d0e779102780d89e3fcd2a12;p=nssm.git diff --git a/registry.cpp b/registry.cpp index 5953f8a..e499933 100644 --- a/registry.cpp +++ b/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; }