From 838c282576cff8e2f0467eab8965ccaee39075f5 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Tue, 1 Mar 2016 10:22:28 +0000 Subject: [PATCH] Not an error if no hook found in the registry. Hooks are optional so we shouldn't log an error if one wasn't found. Thanks Mathias Breiner. --- README.txt | 3 ++- registry.cpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.txt b/README.txt index 6fb7d9a..a95ed94 100644 --- a/README.txt +++ b/README.txt @@ -880,7 +880,8 @@ Thanks to Gerald Haider for noticing that installing a service with NSSM in a path containing spaces was technically a security vulnerability. Thanks to Scott Ware for reporting a crash saving the environment on XP 32-bit. Thanks to Stefan and Michael Scherer for reporting a bug writing the event messages source. -Thanks to Paul Baxter and Mathias Breiner for help with Visual Studio 2015. +Thanks to Paul Baxter for help with Visual Studio 2015. +Thanks to Mathias Breiner for help with Visual Studio and some registry fixes. Licence ------- diff --git a/registry.cpp b/registry.cpp index e3817a4..86eaaf5 100644 --- a/registry.cpp +++ b/registry.cpp @@ -822,8 +822,15 @@ int get_hook(const TCHAR *service_name, const TCHAR *hook_event, const TCHAR *ho log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("hook registry"), _T("get_hook()"), 0); return 1; } - HKEY key = open_registry(service_name, registry, KEY_READ, false); - if (! key) return 1; + HKEY key; + long error = open_registry(service_name, registry, KEY_READ, &key, false); + if (! key) { + if (error == ERROR_FILE_NOT_FOUND) { + ZeroMemory(buffer, buflen); + return 0; + } + return 1; + } int ret = expand_parameter(key, (TCHAR *) hook_action, buffer, buflen, true, false); -- 2.7.4