From: Iain Patterson Date: Wed, 27 Jul 2016 10:54:29 +0000 (+0100) Subject: Allow listing all services. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=d1c0d356f6ea58980a33f2fa2da1b6971dd9f909;p=nssm.git Allow listing all services. To list all services, not just those managed by NSSM, use: nssm list all --- diff --git a/README.txt b/README.txt index e59326f..ae6ca33 100644 --- a/README.txt +++ b/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 -------------------------------------- diff --git a/nssm.cpp b/nssm.cpp index 6aa9a88..ca79a02 100644 --- a/nssm.cpp +++ b/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)); diff --git a/service.cpp b/service.cpp index 88c1820..20ebcd9 100644 --- a/service.cpp +++ b/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); } diff --git a/service.h b/service.h index fa8ac78..a8e0bcf 100644 --- a/service.h +++ b/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