Browse Source

Merge branch 'master' of github.com:slide/winsw

Kohsuke Kawaguchi 12 years ago
parent
commit
87f62cfab4
2 changed files with 45 additions and 10 deletions
  1. 42 9
      Main.cs
  2. 3 1
      WmiSchema.cs

+ 42 - 9
Main.cs

@@ -501,15 +501,48 @@ namespace winsw
                 args[0] = args[0].ToLower();
                 if (args[0] == "install")
                 {
-                    svc.Create(
-                        d.Id,
-                        d.Caption,
-                        "\""+ServiceDescriptor.ExecutablePath+"\"",
-                        WMI.ServiceType.OwnProcess,
-                        ErrorControl.UserNotified,
-                        StartMode.Automatic,
-                        d.Interactive,
-                        d.ServiceDependencies);
+                    if (args.Count > 1 && args[1] == "/p") {
+                        // we expected username/password on stdin
+                        Console.Write("Username: ");
+                        string username = Console.ReadLine ();
+                        Console.Write("Password: ");
+                        StringBuilder password = new StringBuilder ();
+                        ConsoleKeyInfo key;
+                        while (true) {
+                            key = Console.ReadKey (true);
+                            if (key.Key == ConsoleKey.Enter) {
+                                break;
+                            } else if(key.Key == ConsoleKey.Backspace) {
+                                password.Remove (password.Length - 1, 1);
+                                Console.Write ("\b \b");
+                            } else {
+                                Console.Write ('*');
+                                password.Append (key.KeyChar);
+                            }
+                        }
+
+                        svc.Create (
+                            d.Id,
+                            d.Caption,
+                            "\"" + ServiceDescriptor.ExecutablePath + "\"",
+                            WMI.ServiceType.OwnProcess,
+                            ErrorControl.UserNotified,
+                            StartMode.Automatic,
+                            d.Interactive,
+                            username,
+                            password.ToString (),
+                            d.ServiceDependencies);
+                    } else {
+                        svc.Create (
+                            d.Id,
+                            d.Caption,
+                            "\"" + ServiceDescriptor.ExecutablePath + "\"",
+                            WMI.ServiceType.OwnProcess,
+                            ErrorControl.UserNotified,
+                            StartMode.Automatic,
+                            d.Interactive,
+                            d.ServiceDependencies);
+                    }
                     // update the description
                     /* Somehow this doesn't work, even though it doesn't report an error
                     Win32Service s = svc.Select(d.Id);

+ 3 - 1
WmiSchema.cs

@@ -49,6 +49,8 @@ namespace WMI
     {
         // ReturnValue Create(bool desktopInteract, string displayName, int errorControl, string loadOrderGroup, string loadOrderGroupDependencies, string name, string pathName, string serviceDependencies, string serviceType, string startMode, string startName, string startPassword);
         void Create(string name, string displayName, string pathName, ServiceType serviceType, ErrorControl errorControl, StartMode startMode, bool desktopInteract, string[] serviceDependencies);
+        
+        void Create(string name, string displayName, string pathName, ServiceType serviceType, ErrorControl errorControl, StartMode startMode, bool desktopInteract, string startName, string startPassword, string[] serviceDependencies);
 
         Win32Service Select(string name);
     }
@@ -63,4 +65,4 @@ namespace WMI
         void StartService();
         void StopService();
     }
-}
+}