Resend of Adds NET START to net.exe

Rolf Kalbermatter r.kalbermatter at hccnet.nl
Wed May 9 00:51:45 CDT 2007


Tim Schwartz wrote:

+    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);
+        CloseServiceHandle(SCManager);
+        return result;
+    }
+
+    CloseServiceHandle(serviceHandle);
+    CloseServiceHandle(SCManager);
+    HeapFree(GetProcessHeap(), 0, service_display_name);
+    return 0;
+}


I think with a little rearrangment of the code and returning result at the
end you
could avoid duplicating those CloseServiceHandle() and HeapFree() calls.

 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 +88,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;
 }

Me thinks it would be cleaner to only string test for the command in the
main()
and pass in a constant you define somewhere to net_service() that specifies
the
operation to perform. That will allow you to use a switch statement in
net_service()
and make the code a lot easier to read. Also adding new commands won't make
the
whole such a big mess as it would now.

Also consider to use TRUE and FALSE as return value. This being a Windows
tool
and not a Unix one it seems clearer to me.

Rolf Kalbermatter




More information about the wine-devel mailing list