Display canonical service name.
authorIain Patterson <me@iain.cx>
Thu, 26 Dec 2013 19:28:56 +0000 (19:28 +0000)
committerIain Patterson <me@iain.cx>
Fri, 27 Dec 2013 11:12:44 +0000 (11:12 +0000)
When editing or deleting a service we get the service information using the
name provided by the user.  The name is case-insensitive but case-preserving.
Use GetServiceKeyName() to retrieve the canonical name and display that
in any messages containing the service name.

service.cpp

index b246443..177ac15 100644 (file)
@@ -205,6 +205,10 @@ int pre_edit_service(int argc, TCHAR **argv) {
   }\r
   _sntprintf_s(service->displayname, _countof(service->displayname), _TRUNCATE, _T("%s"), qsc->lpDisplayName);\r
 \r
+  /* Get the canonical service name. We open it case insensitively. */\r
+  bufsize = _countof(service->name);\r
+  GetServiceKeyName(services, service->displayname, service->name, &bufsize);\r
+\r
   /* Remember the executable in case it isn't NSSM. */\r
   _sntprintf_s(service->image, _countof(service->image), _TRUNCATE, _T("%s"), qsc->lpBinaryPathName);\r
   HeapFree(GetProcessHeap(), 0, qsc);\r
@@ -440,6 +444,12 @@ int remove_service(nssm_service_t *service) {
     return 3;\r
   }\r
 \r
+  /* Get the canonical service name. We open it case insensitively. */\r
+  unsigned long bufsize = _countof(service->displayname);\r
+  GetServiceDisplayName(services, service->name, service->displayname, &bufsize);\r
+  bufsize = _countof(service->name);\r
+  GetServiceKeyName(services, service->displayname, service->name, &bufsize);\r
+\r
   /* Try to delete the service */\r
   if (! DeleteService(service->handle)) {\r
     print_message(stderr, NSSM_MESSAGE_DELETESERVICE_FAILED);\r