X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=settings.cpp;h=4bbdd57edecad72dcd14a02fe10df4fa7b26336c;hb=3b12cdde22a08bdbc9e4566fcb83cf9d51324af4;hp=c77c1c9434069e322f3a833b8ed0d481fcd4bb38;hpb=2f2f64b07611fe0709bf4d502de7cac292dc1975;p=nssm.git diff --git a/settings.cpp b/settings.cpp index c77c1c9..4bbdd57 100644 --- a/settings.cpp +++ b/settings.cpp @@ -52,7 +52,7 @@ static int setting_set_number(const TCHAR *service_name, void *param, const TCHA } if (str_number(value->string, &number)) return -1; - if (default_value && number == (unsigned long) default_value) { + if (default_value && number == PtrToUlong(default_value)) { error = RegDeleteValue(key, name); if (error == ERROR_SUCCESS || error == ERROR_FILE_NOT_FOUND) return 0; print_message(stderr, NSSM_MESSAGE_REGDELETEVALUE_FAILED, name, service_name, error_string(error)); @@ -726,6 +726,25 @@ int native_get_displayname(const TCHAR *service_name, void *param, const TCHAR * return ret; } +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); + if (! key) return -1; + + int ret = setting_set_environment(service_name, (void *) key, NSSM_NATIVE_ENVIRONMENT, 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); + 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); + RegCloseKey(key); + return ret; +} + int native_set_imagepath(const TCHAR *service_name, void *param, const TCHAR *name, void *default_value, value_t *value, const TCHAR *additional) { SC_HANDLE service_handle = (SC_HANDLE) param; if (! service_handle) return -1; @@ -1039,7 +1058,7 @@ int get_setting(const TCHAR *service_name, HKEY key, settings_t *setting, value_ break; case REG_DWORD: - value->numeric = (unsigned long) setting->default_value; + value->numeric = PtrToUlong(setting->default_value); if (setting->get) ret = setting->get(service_name, (void *) key, setting->name, setting->default_value, value, additional); else ret = -1; break; @@ -1101,6 +1120,7 @@ settings_t settings[] = { { NSSM_NATIVE_DEPENDONSERVICE, REG_MULTI_SZ, NULL, true, ADDITIONAL_CRLF, native_set_dependonservice, native_get_dependonservice }, { NSSM_NATIVE_DESCRIPTION, REG_SZ, _T(""), true, 0, native_set_description, native_get_description }, { NSSM_NATIVE_DISPLAYNAME, REG_SZ, NULL, true, 0, native_set_displayname, native_get_displayname }, + { NSSM_NATIVE_ENVIRONMENT, REG_MULTI_SZ, NULL, true, ADDITIONAL_CRLF, native_set_environment, native_get_environment }, { NSSM_NATIVE_IMAGEPATH, REG_EXPAND_SZ, NULL, true, 0, native_set_imagepath, native_get_imagepath }, { NSSM_NATIVE_OBJECTNAME, REG_SZ, NSSM_LOCALSYSTEM_ACCOUNT, true, 0, native_set_objectname, native_get_objectname }, { NSSM_NATIVE_NAME, REG_SZ, NULL, true, 0, native_set_name, native_get_name },