From 73dbba7a2e6150dea8f58dd2c25ab914a0636308 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Tue, 31 Dec 2013 16:11:08 +0000 Subject: [PATCH] Added get_service_description(). New function to set or unset a service's description. --- service.cpp | 24 +++++++++++++++++------- service.h | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/service.cpp b/service.cpp index cccfa2b..d402ab3 100644 --- a/service.cpp +++ b/service.cpp @@ -65,6 +65,22 @@ QUERY_SERVICE_CONFIG *query_service_config(const TCHAR *service_name, SC_HANDLE return qsc; } +int set_service_description(const TCHAR *service_name, SC_HANDLE service_handle, TCHAR *buffer) { + SERVICE_DESCRIPTION description; + ZeroMemory(&description, sizeof(description)); + /* + lpDescription must be NULL if we aren't changing, the new description + or "". + */ + if (buffer && buffer[0]) description.lpDescription = buffer; + else description.lpDescription = _T(""); + + if (ChangeServiceConfig2(service_handle, SERVICE_CONFIG_DESCRIPTION, &description)) return 0; + + log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SERVICE_CONFIG_DESCRIPTION_FAILED, service_name, error_string(GetLastError()), 0); + return 1; +} + int get_service_description(const TCHAR *service_name, SC_HANDLE service_handle, unsigned long len, TCHAR *buffer) { if (! buffer) return 1; @@ -589,13 +605,7 @@ int edit_service(nssm_service_t *service, bool editing) { } if (service->description[0] || editing) { - SERVICE_DESCRIPTION description; - ZeroMemory(&description, sizeof(description)); - if (service->description[0]) description.lpDescription = service->description; - else description.lpDescription = 0; - if (! ChangeServiceConfig2(service->handle, SERVICE_CONFIG_DESCRIPTION, &description)) { - log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SERVICE_CONFIG_DESCRIPTION_FAILED, service->name, error_string(GetLastError()), 0); - } + set_service_description(service->name, service->handle, service->description); } SERVICE_DELAYED_AUTO_START_INFO delayed; diff --git a/service.h b/service.h index d4d2e0f..a7914a1 100644 --- a/service.h +++ b/service.h @@ -90,6 +90,7 @@ void set_nssm_service_defaults(nssm_service_t *); void cleanup_nssm_service(nssm_service_t *); SC_HANDLE open_service_manager(); QUERY_SERVICE_CONFIG *query_service_config(const TCHAR *, SC_HANDLE); +int set_service_description(const TCHAR *, SC_HANDLE, TCHAR *); int get_service_description(const TCHAR *, SC_HANDLE, unsigned long, TCHAR *); int get_service_startup(const TCHAR *, SC_HANDLE, const QUERY_SERVICE_CONFIG *, unsigned long *); int get_service_username(const TCHAR *, const QUERY_SERVICE_CONFIG *, TCHAR **, size_t *); -- 2.7.4