envlen = newlen;\r
\r
/* Test the environment is valid. */\r
- TCHAR path[MAX_PATH];\r
- GetModuleFileName(0, path, _countof(path));\r
- STARTUPINFO si;\r
- ZeroMemory(&si, sizeof(si));\r
- si.cb = sizeof(si);\r
- PROCESS_INFORMATION pi;\r
- ZeroMemory(&pi, sizeof(pi));\r
- unsigned long flags = CREATE_SUSPENDED;\r
-#ifdef UNICODE\r
- flags |= CREATE_UNICODE_ENVIRONMENT;\r
-#endif\r
-\r
- if (! CreateProcess(0, path, 0, 0, 0, flags, env, 0, &si, &pi)) {\r
- unsigned long error = GetLastError();\r
- if (error == ERROR_INVALID_PARAMETER) {\r
- popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_ENVIRONMENT);\r
- HeapFree(GetProcessHeap(), 0, env);\r
- envlen = 0;\r
- }\r
+ if (test_environment(env)) {\r
+ popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_ENVIRONMENT);\r
+ HeapFree(GetProcessHeap(), 0, env);\r
cleanup_nssm_service(service);\r
return 5;\r
}\r
- TerminateProcess(pi.hProcess, 0);\r
\r
if (SendDlgItemMessage(tablist[NSSM_TAB_ENVIRONMENT], IDC_ENVIRONMENT_REPLACE, BM_GETCHECK, 0, 0) & BST_CHECKED) {\r
service->env = env;\r
flags |= CREATE_UNICODE_ENVIRONMENT;\r
#endif\r
if (! CreateProcess(0, cmd, 0, 0, inherit_handles, flags, service->env, service->dir, &si, &pi)) {\r
+ unsigned long exitcode = 3;\r
unsigned long error = GetLastError();\r
- if (error == ERROR_INVALID_PARAMETER && service->env) log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_CREATEPROCESS_FAILED_INVALID_ENVIRONMENT, service->name, service->exe, NSSM_REG_ENV, 0);\r
+ if (error == ERROR_INVALID_PARAMETER && service->env) {\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_CREATEPROCESS_FAILED_INVALID_ENVIRONMENT, service->name, service->exe, NSSM_REG_ENV, 0);\r
+ if (test_environment(service->env)) exitcode = 4;\r
+ }\r
else log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_CREATEPROCESS_FAILED, service->name, service->exe, error_string(error), 0);\r
close_output_handles(&si);\r
- return stop_service(service, 3, true, true);\r
+ return stop_service(service, exitcode, true, true);\r
}\r
service->process_handle = pi.hProcess;\r
service->pid = pi.dwProcessId;\r