X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=registry.cpp;h=725844b615fc0e7456e8423c7b75e5f6bf2c9fd7;hb=a90eade7d022451e92bedcebe816651df7bf0d17;hp=4abf595013417a710f04629b55adc0ca39af67d3;hpb=2dbaf62e06018a7d0a934c79bd9f39b81dc43694;p=nssm.git diff --git a/registry.cpp b/registry.cpp index 4abf595..725844b 100644 --- a/registry.cpp +++ b/registry.cpp @@ -457,7 +457,7 @@ void override_milliseconds(TCHAR *service_name, HKEY key, TCHAR *value, unsigned if (! ok) *buffer = default_value; } -HKEY open_registry(const TCHAR *service_name, const TCHAR *sub, REGSAM sam) { +HKEY open_registry(const TCHAR *service_name, const TCHAR *sub, REGSAM sam, bool must_exist) { /* Get registry */ TCHAR registry[KEY_LENGTH]; HKEY key; @@ -477,7 +477,9 @@ HKEY open_registry(const TCHAR *service_name, const TCHAR *sub, REGSAM sam) { } } else { - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, registry, 0, sam, &key) != ERROR_SUCCESS) { + long error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, registry, 0, sam, &key); + if (error != ERROR_SUCCESS) { + if (error == ERROR_FILE_NOT_FOUND && ! must_exist) return 0; log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OPENKEY_FAILED, registry, error_string(GetLastError()), 0); return 0; } @@ -486,8 +488,12 @@ HKEY open_registry(const TCHAR *service_name, const TCHAR *sub, REGSAM sam) { return key; } +HKEY open_registry(const TCHAR *service_name, const TCHAR *sub, REGSAM sam) { + return open_registry(service_name, sub, sam, true); +} + HKEY open_registry(const TCHAR *service_name, REGSAM sam) { - return open_registry(service_name, 0, sam); + return open_registry(service_name, 0, sam, true); } int get_io_parameters(nssm_service_t *service, HKEY key) {