mirror of https://github.com/winsw/winsw
A bit of refactoring to avoid duplication and readability.
Still needs to verify that this doesn't cause any regressions.pull/21/merge
parent
87f62cfab4
commit
c863e7fc33
56
Main.cs
56
Main.cs
|
@ -501,24 +501,13 @@ namespace winsw
|
||||||
args[0] = args[0].ToLower();
|
args[0] = args[0].ToLower();
|
||||||
if (args[0] == "install")
|
if (args[0] == "install")
|
||||||
{
|
{
|
||||||
|
string username=null, password=null;
|
||||||
if (args.Count > 1 && args[1] == "/p") {
|
if (args.Count > 1 && args[1] == "/p") {
|
||||||
// we expected username/password on stdin
|
// we expected username/password on stdin
|
||||||
Console.Write("Username: ");
|
Console.Write("Username: ");
|
||||||
string username = Console.ReadLine ();
|
username = Console.ReadLine();
|
||||||
Console.Write("Password: ");
|
Console.Write("Password: ");
|
||||||
StringBuilder password = new StringBuilder ();
|
password = ReadPassword();
|
||||||
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 (
|
svc.Create (
|
||||||
|
@ -530,19 +519,9 @@ namespace winsw
|
||||||
StartMode.Automatic,
|
StartMode.Automatic,
|
||||||
d.Interactive,
|
d.Interactive,
|
||||||
username,
|
username,
|
||||||
password.ToString (),
|
password,
|
||||||
d.ServiceDependencies);
|
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
|
// update the description
|
||||||
/* Somehow this doesn't work, even though it doesn't report an error
|
/* Somehow this doesn't work, even though it doesn't report an error
|
||||||
Win32Service s = svc.Select(d.Id);
|
Win32Service s = svc.Select(d.Id);
|
||||||
|
@ -627,5 +606,30 @@ namespace winsw
|
||||||
}
|
}
|
||||||
ServiceBase.Run(new WrapperService());
|
ServiceBase.Run(new WrapperService());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string ReadPassword()
|
||||||
|
{
|
||||||
|
StringBuilder buf = new StringBuilder();
|
||||||
|
ConsoleKeyInfo key;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
key = Console.ReadKey(true);
|
||||||
|
if (key.Key == ConsoleKey.Enter)
|
||||||
|
{
|
||||||
|
return buf.ToString();
|
||||||
|
}
|
||||||
|
else if (key.Key == ConsoleKey.Backspace)
|
||||||
|
{
|
||||||
|
buf.Remove(buf.Length - 1, 1);
|
||||||
|
Console.Write("\b \b");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.Write('*');
|
||||||
|
buf.Append(key.KeyChar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,6 @@ namespace WMI
|
||||||
public interface Win32Services : IWmiCollection
|
public interface Win32Services : IWmiCollection
|
||||||
{
|
{
|
||||||
// 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);
|
// 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);
|
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);
|
Win32Service Select(string name);
|
||||||
|
|
Loading…
Reference in New Issue