From: Iain Patterson Date: Sun, 8 Mar 2015 17:24:58 +0000 (+0000) Subject: Clean up Parameters properly. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=e072e7ea67ab219eadb6761ceba4762b345a9b1f;hp=cfa1e729fd2e5f953153239080b17ddb70de733e;p=nssm.git 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. --- 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; }