if (! ok) *buffer = default_value;\r
}\r
\r
-HKEY open_registry(const TCHAR *service_name, const TCHAR *sub, REGSAM sam, bool must_exist) {\r
- /* Get registry */\r
- TCHAR registry[KEY_LENGTH];\r
- HKEY key;\r
+static int service_registry_path(const TCHAR *service_name, bool parameters, const TCHAR *sub, TCHAR *buffer, unsigned long buflen) {\r
int ret;\r
\r
- if (sub) ret = _sntprintf_s(registry, _countof(registry), _TRUNCATE, NSSM_REGISTRY _T("\\%s"), service_name, sub);\r
- else ret = _sntprintf_s(registry, _countof(registry), _TRUNCATE, NSSM_REGISTRY, service_name);\r
- if (ret < 0) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, _T("NSSM_REGISTRY"), _T("open_registry()"), 0);\r
- return 0;\r
+ if (parameters) {\r
+ if (sub) ret = _sntprintf_s(buffer, buflen, _TRUNCATE, NSSM_REGISTRY _T("\\") NSSM_REG_PARAMETERS _T("\\%s"), service_name, sub);\r
+ else ret = _sntprintf_s(buffer, buflen, _TRUNCATE, NSSM_REGISTRY _T("\\") NSSM_REG_PARAMETERS, service_name);\r
}\r
+ else ret = _sntprintf_s(buffer, buflen, _TRUNCATE, NSSM_REGISTRY, service_name);\r
+\r
+ return ret;\r
+}\r
+\r
+static HKEY open_registry_key(const TCHAR *registry, REGSAM sam, bool must_exist) {\r
+ HKEY key;\r
\r
if (sam & KEY_SET_VALUE) {\r
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, registry, 0, 0, REG_OPTION_NON_VOLATILE, sam, 0, &key, 0) != ERROR_SUCCESS) {\r
return key;\r
}\r
\r
+HKEY open_service_registry(const TCHAR *service_name, REGSAM sam, bool must_exist) {\r
+ /* Get registry */\r
+ TCHAR registry[KEY_LENGTH];\r
+ if (service_registry_path(service_name, false, 0, registry, _countof(registry)) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, NSSM_REGISTRY, _T("open_service_registry()"), 0);\r
+ return 0;\r
+ }\r
+\r
+ return open_registry_key(registry, sam, must_exist);\r
+}\r
+\r
+HKEY open_registry(const TCHAR *service_name, const TCHAR *sub, REGSAM sam, bool must_exist) {\r
+ /* Get registry */\r
+ TCHAR registry[KEY_LENGTH];\r
+ if (service_registry_path(service_name, true, sub, registry, _countof(registry)) < 0) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, NSSM_REGISTRY, _T("open_registry()"), 0);\r
+ return 0;\r
+ }\r
+\r
+ return open_registry_key(registry, sam, must_exist);\r
+}\r
+\r
HKEY open_registry(const TCHAR *service_name, const TCHAR *sub, REGSAM sam) {\r
return open_registry(service_name, sub, sam, true);\r
}\r
#ifndef REGISTRY_H\r
#define REGISTRY_H\r
\r
-#define NSSM_REGISTRY _T("SYSTEM\\CurrentControlSet\\Services\\%s\\Parameters")\r
+#define NSSM_REGISTRY _T("SYSTEM\\CurrentControlSet\\Services\\%s")\r
+#define NSSM_REG_PARAMETERS _T("Parameters")\r
#define NSSM_REGISTRY_GROUPS _T("SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder")\r
#define NSSM_REG_GROUPS _T("List")\r
#define NSSM_REG_EXE _T("Application")\r
#define NSSM_REG_HOOK _T("AppEvents")\r
#define NSSM_STDIO_LENGTH 29\r
\r
+HKEY open_service_registry(const TCHAR *, REGSAM sam, bool);\r
HKEY open_registry(const TCHAR *, const TCHAR *, REGSAM sam, bool);\r
HKEY open_registry(const TCHAR *, const TCHAR *, REGSAM sam);\r
HKEY open_registry(const TCHAR *, REGSAM sam);\r
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;
{ 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 },
#define NSSM_NATIVE_DEPENDONSERVICE _T("DependOnService")
#define NSSM_NATIVE_DESCRIPTION _T("Description")
#define NSSM_NATIVE_DISPLAYNAME _T("DisplayName")
+#define NSSM_NATIVE_ENVIRONMENT _T("Environment")
#define NSSM_NATIVE_IMAGEPATH _T("ImagePath")
#define NSSM_NATIVE_NAME _T("Name")
#define NSSM_NATIVE_OBJECTNAME _T("ObjectName")