SC_HANDLE service_handle = OpenService(services, service_name, access);\r
if (service_handle) {\r
if (canonical_name && canonical_name != service_name) {\r
- if (_sntprintf_s(canonical_name, canonical_namelen, _TRUNCATE, _T("%s"), service_name) < 0) {\r
- print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("canonical_name"), _T("open_service()"));\r
- return 0;\r
- }\r
+ TCHAR displayname[SERVICE_NAME_LENGTH];\r
+ unsigned long displayname_len = (unsigned long) _countof(displayname);\r
+ GetServiceDisplayName(services, service_name, displayname, &displayname_len);\r
+ unsigned long keyname_len = canonical_namelen;\r
+ GetServiceKeyName(services, displayname, canonical_name, &keyname_len);\r
}\r
return service_handle;\r
}\r