From: Iain Patterson Date: Sun, 2 Mar 2014 14:22:53 +0000 (+0000) Subject: Really get canonical name in open_service(). X-Git-Tag: v2.22~5 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=14d5a10605085a499136744b66936c75b6f0ccd4;p=nssm.git Really get canonical name in open_service(). The open_service() function would return the canonical service name if passed a display name but would return the requested name as-is when called with a valid service name. We now retrieve the display name and map back to the key name so that the returned string is capitalised exactly as it appears in the services database. --- diff --git a/service.cpp b/service.cpp index 3205dcc..4b14d17 100644 --- a/service.cpp +++ b/service.cpp @@ -268,10 +268,11 @@ SC_HANDLE open_service(SC_HANDLE services, TCHAR *service_name, unsigned long ac SC_HANDLE service_handle = OpenService(services, service_name, access); if (service_handle) { if (canonical_name && canonical_name != service_name) { - if (_sntprintf_s(canonical_name, canonical_namelen, _TRUNCATE, _T("%s"), service_name) < 0) { - print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("canonical_name"), _T("open_service()")); - return 0; - } + TCHAR displayname[SERVICE_NAME_LENGTH]; + unsigned long displayname_len = (unsigned long) _countof(displayname); + GetServiceDisplayName(services, service_name, displayname, &displayname_len); + unsigned long keyname_len = canonical_namelen; + GetServiceKeyName(services, displayname, canonical_name, &keyname_len); } return service_handle; }