[PATCH] Adds NET START to net.exe

Tim Schwartz tim at sanityinternet.com
Mon May 7 10:45:00 CDT 2007


---
 programs/net/Makefile.in |    2 +-
 programs/net/net.c       |   76
+++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/programs/net/Makefile.in b/programs/net/Makefile.in
index 5db7fc0..9037323 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   = kernel32 advapi32
 
 C_SRCS = net.c
 
diff --git a/programs/net/net.c b/programs/net/net.c
index f77c820..ef08250 100644
--- a/programs/net/net.c
+++ b/programs/net/net.c
@@ -18,15 +18,66 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <windows.h>
+
+int net_service(char *operation, char *service_name)
+{
+    SC_HANDLE SCManager, serviceHandle;
+    int result = 0;
+    unsigned int *buffer_size = NULL;
+    char *service_display_name = NULL;
+
+    SCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+    if(!SCManager)
+    {
+        printf("Couldn't get handle to SCManager.\n");
+        return 0;
+    }
+    serviceHandle = OpenService(SCManager, service_name,
SC_MANAGER_ALL_ACCESS);
+    if(!serviceHandle)
+    {
+        printf("Couldn't get handle to service.\n");
+        CloseServiceHandle(SCManager);
+        return 0;
+    }
+
+    GetServiceDisplayName(SCManager, service_name, NULL, buffer_size);
+    if(!buffer_size)
+    {
+        service_display_name = HeapAlloc(GetProcessHeap(), 0,
strlen(service_name));
+        strcpy(service_display_name, service_name);
+    }
+    else
+    {
+        service_display_name = HeapAlloc(GetProcessHeap(), 0,
*buffer_size);
+        GetServiceDisplayName(SCManager, service_name,
service_display_name, buffer_size);
+    }
+
+    if(!strcasecmp(operation, "start"))
+    {
+        printf("The %s service is starting.\n", service_display_name);
+        result = StartService(serviceHandle,0,NULL);
+        CloseServiceHandle(serviceHandle);
+        if(!result) printf("The %s service failed to start.\n",
service_display_name);
+        else printf("The %s service was started successfully.\n",
service_display_name);
+
+        HeapFree(GetProcessHeap(), 0, service_display_name);
+        return result;
+    }
+
+    CloseServiceHandle(SCManager);
+    CloseServiceHandle(serviceHandle);
+    HeapFree(GetProcessHeap(), 0, service_display_name);
+    return 0;
+}
 
 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 +86,24 @@ 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(argv[1], argv[2]))
+        {
+            return 1;
+        }
+        return 0;
+    }
+
+ 
+    return 0;
 }
-- 
1.4.4.2





More information about the wine-patches mailing list