Browse Source

Allow listing all services.

To list all services, not just those managed by NSSM, use:

    nssm list all
Iain Patterson 5 years ago
parent
commit
d1c0d356f6
4 changed files with 10 additions and 4 deletions
  1. 4 0
      README.txt
  2. 1 1
      nssm.cpp
  3. 4 2
      service.cpp
  4. 1 1
      service.h

+ 4 - 0
README.txt

@@ -870,6 +870,10 @@ The following command will print the names of all services managed by NSSM:
 
     nssm list
 
+To see all services on the system, not just NSSM's, use list all:
+
+    nssm list all
+
 
 Showing processes started by a service
 --------------------------------------

+ 1 - 1
nssm.cpp

@@ -272,7 +272,7 @@ int _tmain(int argc, TCHAR **argv) {
       for (int i = 0; i < argc; i++) SecureZeroMemory(argv[i], _tcslen(argv[i]) * sizeof(TCHAR));
       exit(ret);
     }
-    if (str_equiv(argv[1], _T("list"))) exit(list_nssm_services());
+    if (str_equiv(argv[1], _T("list"))) exit(list_nssm_services(argc - 2, argv + 2));
     if (str_equiv(argv[1], _T("processes"))) exit(service_process_tree(argc - 2, argv + 2));
     if (str_equiv(argv[1], _T("remove"))) {
       if (! is_admin) exit(elevate(argc, argv, NSSM_MESSAGE_NOT_ADMINISTRATOR_CANNOT_REMOVE));

+ 4 - 2
service.cpp

@@ -2212,7 +2212,9 @@ awaited:
   return ret;
 }
 
-int list_nssm_services() {
+int list_nssm_services(int argc, TCHAR **argv) {
+  bool including_native = (argc > 0 && str_equiv(argv[0], _T("all")));
+
   /* Open service manager. */
   SC_HANDLE services = open_service_manager(SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE);
   if (! services) {
@@ -2259,7 +2261,7 @@ int list_nssm_services() {
 
       get_parameters(service, 0);
       /* We manage the service if we have an Application. */
-      if (service->exe[0]) _tprintf(_T("%s\n"), service->name);
+      if (including_native || service->exe[0]) _tprintf(_T("%s\n"), service->name);
 
       cleanup_nssm_service(service);
     }

+ 1 - 1
service.h

@@ -163,7 +163,7 @@ int stop_service(nssm_service_t *, unsigned long, bool, bool);
 void CALLBACK end_service(void *, unsigned char);
 void throttle_restart(nssm_service_t *);
 int await_single_handle(SERVICE_STATUS_HANDLE, SERVICE_STATUS *, HANDLE, TCHAR *, TCHAR *, unsigned long);
-int list_nssm_services();
+int list_nssm_services(int, TCHAR **);
 int service_process_tree(int, TCHAR **);
 
 #endif