return qsc;\r
}\r
\r
+int get_service_description(const TCHAR *service_name, SC_HANDLE service_handle, unsigned long len, TCHAR *buffer) {\r
+ if (! buffer) return 1;\r
+\r
+ unsigned long bufsize;\r
+ QueryServiceConfig2(service_handle, SERVICE_CONFIG_DESCRIPTION, 0, 0, &bufsize);\r
+ unsigned long error = GetLastError();\r
+ if (error == ERROR_INSUFFICIENT_BUFFER) {\r
+ SERVICE_DESCRIPTION *description = (SERVICE_DESCRIPTION *) HeapAlloc(GetProcessHeap(), 0, bufsize);\r
+ if (! description) {\r
+ print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("SERVICE_CONFIG_DESCRIPTION"), _T("get_service_description()"));\r
+ return 2;\r
+ }\r
+\r
+ if (QueryServiceConfig2(service_handle, SERVICE_CONFIG_DESCRIPTION, (unsigned char *) description, bufsize, &bufsize)) {\r
+ if (description->lpDescription) _sntprintf_s(buffer, len, _TRUNCATE, _T("%s"), description->lpDescription);\r
+ else ZeroMemory(buffer, len * sizeof(TCHAR));\r
+ HeapFree(GetProcessHeap(), 0, description);\r
+ return 0;\r
+ }\r
+ else {\r
+ HeapFree(GetProcessHeap(), 0, description);\r
+ print_message(stderr, NSSM_MESSAGE_QUERYSERVICECONFIG2_FAILED, service_name, _T("SERVICE_CONFIG_DESCRIPTION"), error_string(error));\r
+ return 3;\r
+ }\r
+ }\r
+ else {\r
+ print_message(stderr, NSSM_MESSAGE_QUERYSERVICECONFIG2_FAILED, service_name, _T("SERVICE_CONFIG_DESCRIPTION"), error_string(error));\r
+ return 4;\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
int get_service_startup(const TCHAR *service_name, SC_HANDLE service_handle, const QUERY_SERVICE_CONFIG *qsc, unsigned long *startup) {\r
if (! qsc) return 1;\r
\r
\r
/* Get system details. */\r
unsigned long bufsize;\r
- unsigned long error;\r
QUERY_SERVICE_CONFIG *qsc = query_service_config(service->name, service->handle);\r
if (! qsc) {\r
CloseHandle(service->handle);\r
HeapFree(GetProcessHeap(), 0, qsc);\r
\r
/* Get extended system details. */\r
- QueryServiceConfig2(service->handle, SERVICE_CONFIG_DESCRIPTION, 0, 0, &bufsize);\r
- error = GetLastError();\r
- if (error == ERROR_INSUFFICIENT_BUFFER) {\r
- SERVICE_DESCRIPTION *description = (SERVICE_DESCRIPTION *) HeapAlloc(GetProcessHeap(), 0, bufsize);\r
- if (! description) {\r
- CloseHandle(service->handle);\r
- CloseServiceHandle(services);\r
- print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("SERVICE_CONFIG_DESCRIPTION"), _T("pre_edit_service()"));\r
- return 6;\r
- }\r
-\r
- if (QueryServiceConfig2(service->handle, SERVICE_CONFIG_DESCRIPTION, (unsigned char *) description, bufsize, &bufsize)) {\r
- if (description->lpDescription) _sntprintf_s(service->description, _countof(service->description), _TRUNCATE, _T("%s"), description->lpDescription);\r
- HeapFree(GetProcessHeap(), 0, description);\r
- }\r
- else {\r
- HeapFree(GetProcessHeap(), 0, description);\r
- CloseHandle(service->handle);\r
- CloseServiceHandle(services);\r
- print_message(stderr, NSSM_MESSAGE_QUERYSERVICECONFIG2_FAILED, service->name, _T("SERVICE_CONFIG_DELAYED_AUTO_START_INFO"), error_string(error));\r
- return 6;\r
- }\r
- }\r
- else {\r
+ if (get_service_description(service->name, service->handle, _countof(service->description), service->description)) {\r
CloseHandle(service->handle);\r
CloseServiceHandle(services);\r
- print_message(stderr, NSSM_MESSAGE_QUERYSERVICECONFIG2_FAILED, service->name, _T("SERVICE_CONFIG_DELAYED_AUTO_START_INFO"), error_string(error));\r
return 6;\r
}\r
\r