Tim Schwartz : net.exe: Add NET START command.
Alexandre Julliard
julliard at wine.codeweavers.com
Wed May 30 08:56:56 CDT 2007
Module: wine
Branch: master
Commit: 9aaaafa77459573115910a53da1e3f9dacba9f6c
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9aaaafa77459573115910a53da1e3f9dacba9f6c
Author: Tim Schwartz <tim at sanityinternet.com>
Date: Mon May 28 10:02:48 2007 -0500
net.exe: Add NET START command.
---
programs/net/Makefile.in | 2 +-
programs/net/net.c | 68 +++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 65 insertions(+), 5 deletions(-)
diff --git a/programs/net/Makefile.in b/programs/net/Makefile.in
index 5db7fc0..d72a9ba 100644
--- a/programs/net/Makefile.in
+++ b/programs/net/Makefile.in
@@ -4,7 +4,7 @@ SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = net.exe
APPMODE = -mconsole
-IMPORTS = kernel32
+IMPORTS = advapi32 kernel32
C_SRCS = net.c
diff --git a/programs/net/net.c b/programs/net/net.c
index f77c820..3a6c39a 100644
--- a/programs/net/net.c
+++ b/programs/net/net.c
@@ -18,15 +18,59 @@
#include <stdio.h>
#include <string.h>
+#include <windows.h>
+
+#define NET_START 0001
+
+static BOOL net_service(int operation, char *service_name)
+{
+ SC_HANDLE SCManager, serviceHandle;
+ BOOL result = 0;
+ char service_display_name[4096];
+ DWORD buffer_size = sizeof(service_display_name);
+
+ SCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+ if(!SCManager)
+ {
+ printf("Couldn't get handle to SCManager.\n");
+ return FALSE;
+ }
+ serviceHandle = OpenService(SCManager, service_name, SC_MANAGER_ALL_ACCESS);
+ if(!serviceHandle)
+ {
+ printf("Couldn't get handle to service.\n");
+ CloseServiceHandle(SCManager);
+ return FALSE;
+ }
+
+
+ GetServiceDisplayName(SCManager, service_name, service_display_name, &buffer_size);
+ if (!service_display_name[0]) strcpy(service_display_name, service_name);
+
+ switch(operation)
+ {
+ case NET_START:
+ printf("The %s service is starting.\n", service_display_name);
+ result = StartService(serviceHandle, 0, NULL);
+
+ printf("The %s service ", service_display_name);
+ if(!result) printf("failed to start.\n");
+ else printf("was started successfully.\n");
+ break;
+ }
+
+ CloseServiceHandle(serviceHandle);
+ CloseServiceHandle(SCManager);
+ return result;
+}
int main(int argc, char *argv[])
{
- int ret = 0;
if (argc < 2)
{
printf("The syntax of this command is:\n\n");
- printf("NET [ HELP ]\n");
+ printf("NET [ HELP | START ]\n");
return 1;
}
@@ -35,7 +79,23 @@ int main(int argc, char *argv[])
printf("The syntax of this command is:\n\n");
printf("NET HELP command\n -or-\nNET command /HELP\n\n");
printf(" Commands available are:\n");
- printf(" NET HELP\n");
+ printf(" NET HELP NET START\n");
}
- return ret;
+
+ if(!strcasecmp(argv[1], "start"))
+ {
+ if(argc < 3)
+ {
+ printf("Specify service name to start.\n");
+ return 1;
+ }
+
+ if(!net_service(NET_START, argv[2]))
+ {
+ return 1;
+ }
+ return 0;
+ }
+
+ return 0;
}
More information about the wine-cvs
mailing list