From: Iain Patterson Date: Fri, 22 Jul 2016 13:20:07 +0000 (+0100) Subject: Ensure we have the right key for querying Environment. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;ds=sidebyside;h=8835843825b95ec9597ea958055e55499e1aa1c9;p=nssm.git Ensure we have the right key for querying Environment. The Environment value is under the service key not our subkey. If we're querying it we should expect that the service definition exists in the registry. --- diff --git a/registry.cpp b/registry.cpp index 6974270..7c93a3d 100644 --- a/registry.cpp +++ b/registry.cpp @@ -242,7 +242,7 @@ int get_environment(TCHAR *service_name, HKEY key, TCHAR *value, TCHAR **env, un *env = 0; /* The service probably doesn't have any environment configured */ if (ret == ERROR_FILE_NOT_FOUND) return 0; - log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(GetLastError()), 0); + log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(ret), 0); return 1; } diff --git a/settings.cpp b/settings.cpp index 7d08e13..c85bab4 100644 --- a/settings.cpp +++ b/settings.cpp @@ -727,20 +727,20 @@ int native_get_displayname(const TCHAR *service_name, void *param, const TCHAR * } int native_set_environment(const TCHAR *service_name, void *param, const TCHAR *name, void *default_value, value_t *value, const TCHAR *additional) { - HKEY key = open_service_registry(service_name, KEY_SET_VALUE, false); + HKEY key = open_service_registry(service_name, KEY_SET_VALUE, true); if (! key) return -1; - int ret = setting_set_environment(service_name, (void *) key, NSSM_NATIVE_ENVIRONMENT, default_value, value, additional); + int ret = setting_set_environment(service_name, (void *) key, name, default_value, value, additional); RegCloseKey(key); return ret; } int native_get_environment(const TCHAR *service_name, void *param, const TCHAR *name, void *default_value, value_t *value, const TCHAR *additional) { - HKEY key = open_service_registry(service_name, KEY_READ, false); + HKEY key = open_service_registry(service_name, KEY_READ, true); if (! key) return -1; ZeroMemory(value, sizeof(value_t)); - int ret = setting_get_environment(service_name, (void *) key, NSSM_NATIVE_ENVIRONMENT, default_value, value, additional); + int ret = setting_get_environment(service_name, (void *) key, name, default_value, value, additional); RegCloseKey(key); return ret; }