Set the environment before querying the registry.
[nssm.git] / registry.cpp
index 00d6eaf..de3127f 100644 (file)
@@ -531,6 +531,14 @@ int get_parameters(nssm_service_t *service, STARTUPINFO *si) {
   /* Don't expand parameters when retrieving for the GUI. */\r
   bool expand = si ? true : false;\r
 \r
+  /* Try to get environment variables - may fail */\r
+  get_environment(service->name, key, NSSM_REG_ENV, &service->env, &service->envlen);\r
+  /* Environment variables to add to existing rather than replace - may fail. */\r
+  get_environment(service->name, key, NSSM_REG_ENV_EXTRA, &service->env_extra, &service->env_extralen);\r
+\r
+  /* Set environment if we are starting the service. */\r
+  if (si) set_service_environment(service);\r
+\r
   /* Try to get executable file - MUST succeed */\r
   if (get_string(key, NSSM_REG_EXE, service->exe, sizeof(service->exe), expand, false, true)) {\r
     RegCloseKey(key);\r
@@ -585,11 +593,6 @@ int get_parameters(nssm_service_t *service, STARTUPINFO *si) {
     }\r
   }\r
 \r
-  /* Try to get environment variables - may fail */\r
-  get_environment(service->name, key, NSSM_REG_ENV, &service->env, &service->envlen);\r
-  /* Environment variables to add to existing rather than replace - may fail. */\r
-  get_environment(service->name, key, NSSM_REG_ENV_EXTRA, &service->env_extra, &service->env_extralen);\r
-\r
   /* Try to get priority - may fail. */\r
   unsigned long priority;\r
   if (get_number(key, NSSM_REG_PRIORITY, &priority, false) == 1) {\r