[2/2] net: Add support for enumerating the running services with 'net start'.
Francois Gouget
fgouget at codeweavers.com
Fri Aug 26 10:41:52 CDT 2011
---
Quite useful to see what services are actually running.
programs/net/net.c | 55 ++++++++++++++++++++++++++++++++++++++++++++-
programs/net/net.rc | 4 ++-
programs/net/resources.h | 2 +
3 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/programs/net/net.c b/programs/net/net.c
index 249c14d..ed26b43 100644
--- a/programs/net/net.c
+++ b/programs/net/net.c
@@ -19,9 +19,12 @@
#include <windows.h>
#include <lm.h>
#include <wine/unicode.h>
+#include <wine/debug.h>
#include "resources.h"
+WINE_DEFAULT_DEBUG_CHANNEL(net);
+
#define NET_START 0001
#define NET_STOP 0002
@@ -131,6 +134,49 @@ static BOOL net_use(int argc, const WCHAR* argv[])
return FALSE;
}
+static BOOL net_enum_services(void)
+{
+ SC_HANDLE SCManager;
+ LPENUM_SERVICE_STATUS_PROCESSW services;
+ DWORD size, i, count, resume;
+ BOOL success = FALSE;
+
+ SCManager = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+ if(!SCManager)
+ {
+ output_string(STRING_NO_SCM);
+ return FALSE;
+ }
+
+ EnumServicesStatusExW(SCManager, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_ACTIVE, NULL, 0, &size, &count, NULL, NULL);
+ if(GetLastError() != ERROR_MORE_DATA)
+ {
+ output_error_string(GetLastError());
+ goto end;
+ }
+ services = HeapAlloc(GetProcessHeap(), 0, size);
+ resume = 0;
+ if(!EnumServicesStatusExW(SCManager, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_ACTIVE, (LPBYTE)services, size, &size, &count, &resume, NULL))
+ {
+ output_error_string(GetLastError());
+ goto end;
+ }
+ output_string(STRING_RUNNING_HEADER);
+ for(i = 0; i < count; i++)
+ {
+ output_string(STRING_RUNNING, services[i].lpDisplayName);
+ WINE_TRACE("service=%s state=%d controls=%x\n",
+ wine_dbgstr_w(services[i].lpServiceName),
+ services[i].ServiceStatusProcess.dwCurrentState,
+ services[i].ServiceStatusProcess.dwControlsAccepted);
+ }
+ success = TRUE;
+
+ end:
+ CloseServiceHandle(SCManager);
+ return success;
+}
+
static BOOL StopService(SC_HANDLE SCManager, SC_HANDLE serviceHandle)
{
LPENUM_SERVICE_STATUSW dependencies = NULL;
@@ -256,12 +302,17 @@ int wmain(int argc, const WCHAR* argv[])
}
else if(arg_is(argv[1], startW))
{
- if(argc != 3)
+ if(argc > 3)
{
output_string(STRING_START_USAGE);
return 1;
}
- if(arg_is(argv[2], shelpW))
+ if (argc == 2)
+ {
+ if (!net_enum_services())
+ return 1;
+ }
+ else if(arg_is(argv[2], shelpW))
output_string(STRING_START_USAGE);
else if(!net_service(NET_START, argv[2]))
return 1;
diff --git a/programs/net/net.rc b/programs/net/net.rc
index 3f0ddef..10bb678 100644
--- a/programs/net/net.rc
+++ b/programs/net/net.rc
@@ -25,7 +25,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
STRINGTABLE
{
STRING_USAGE, "The syntax of this command is:\n\nNET command [arguments]\n -or-\nNET command /HELP\n\nWhere 'command' is one of HELP, START, STOP or USE\n"
- STRING_START_USAGE, "The syntax of this command is:\n\nNET START service\n\nWhere 'service' is the name of the service to start.\n"
+ STRING_START_USAGE, "The syntax of this command is:\n\nNET START [service]\n\nDisplays the list of running services if 'service' is omitted. Otherwise 'service' is the name of the service to start.\n"
STRING_STOP_USAGE, "The syntax of this command is:\n\nNET STOP service\n\nWhere 'service' is the name of the service to stop.\n"
STRING_STOP_DEP, "Stopping dependent service: %s\n"
STRING_CANT_STOP, "Could not stop service %s\n"
@@ -37,6 +37,8 @@ STRINGTABLE
STRING_STOP_SVC, "The %s service is stopping.\n"
STRING_STOP_SVC_SUCCESS, "The %s service was stopped successfully.\n"
STRING_STOP_SVC_FAIL, "The %s service failed to stop.\n"
+ STRING_RUNNING_HEADER, "The following services are running:\n"
+ STRING_RUNNING, " %s\n"
STRING_NO_ENTRIES, "There are no entries in the list.\n"
STRING_USE_HEADER, "\nStatus Local Remote\n---------------------------------------------------------------\n"
STRING_USE_ENTRY, "%s %s %s Open resources: %lu\n"
diff --git a/programs/net/resources.h b/programs/net/resources.h
index 5accad7..35aebe3 100644
--- a/programs/net/resources.h
+++ b/programs/net/resources.h
@@ -40,3 +40,5 @@
#define STRING_NETERR 121
#define STRING_CONN 122
#define STRING_RECONN 123
+#define STRING_RUNNING_HEADER 124
+#define STRING_RUNNING 125
--
1.7.5.4
More information about the wine-patches
mailing list