return ret;\r
}\r
\r
+QUERY_SERVICE_CONFIG *query_service_config(const TCHAR *service_name, SC_HANDLE service_handle) {\r
+ QUERY_SERVICE_CONFIG *qsc;\r
+ unsigned long bufsize;\r
+ unsigned long error;\r
+\r
+ QueryServiceConfig(service_handle, 0, 0, &bufsize);\r
+ error = GetLastError();\r
+ if (error == ERROR_INSUFFICIENT_BUFFER) {\r
+ qsc = (QUERY_SERVICE_CONFIG *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bufsize);\r
+ if (! qsc) {\r
+ print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("QUERY_SERVICE_CONFIG"), _T("query_service_config()"), 0);\r
+ return 0;\r
+ }\r
+ }\r
+ else {\r
+ print_message(stderr, NSSM_MESSAGE_QUERYSERVICECONFIG_FAILED, service_name, error_string(error), 0);\r
+ return 0;\r
+ }\r
+\r
+ if (! QueryServiceConfig(service_handle, qsc, bufsize, &bufsize)) {\r
+ HeapFree(GetProcessHeap(), 0, qsc);\r
+ print_message(stderr, NSSM_MESSAGE_QUERYSERVICECONFIG_FAILED, service_name, error_string(GetLastError()), 0);\r
+ return 0;\r
+ }\r
+\r
+ return qsc;\r
+}\r
+\r
static int grant_logon_as_service(const TCHAR *username) {\r
if (str_equiv(username, NSSM_LOCALSYSTEM_ACCOUNT)) return 0;\r
\r
/* Get system details. */\r
unsigned long bufsize;\r
unsigned long error;\r
- QUERY_SERVICE_CONFIG *qsc;\r
-\r
- QueryServiceConfig(service->handle, 0, 0, &bufsize);\r
- error = GetLastError();\r
- if (error == ERROR_INSUFFICIENT_BUFFER) {\r
- qsc = (QUERY_SERVICE_CONFIG *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bufsize);\r
- if (! qsc) {\r
- print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("QUERY_SERVICE_CONFIG"), _T("pre_edit_service()"), 0);\r
- return 4;\r
- }\r
- }\r
- else {\r
- CloseHandle(service->handle);\r
- CloseServiceHandle(services);\r
- print_message(stderr, NSSM_MESSAGE_QUERYSERVICECONFIG_FAILED, service->name, error_string(error), 0);\r
- return 4;\r
- }\r
-\r
- if (! QueryServiceConfig(service->handle, qsc, bufsize, &bufsize)) {\r
- HeapFree(GetProcessHeap(), 0, qsc);\r
+ QUERY_SERVICE_CONFIG *qsc = query_service_config(service->name, service->handle);\r
+ if (! qsc) {\r
CloseHandle(service->handle);\r
CloseServiceHandle(services);\r
- print_message(stderr, NSSM_MESSAGE_QUERYSERVICECONFIG_FAILED, service->name, error_string(GetLastError()), 0);\r
return 4;\r
}\r
\r