Skip to content

Commit

Permalink
Added ability to set custom account when installing windows service
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafal Klys committed Sep 13, 2011
1 parent 9a269c0 commit 8255b18
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
12 changes: 11 additions & 1 deletion Rhino.ServiceBus.Host/Actions/InstallAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ public void Execute(ExecutingOptions options)
Description = options.Name,
Context = new InstallContext()
};


if (!string.IsNullOrEmpty(options.Account))
{
if (string.IsNullOrEmpty(options.Password))
{
throw new InvalidOperationException("When /Action is Install and /Account is set /Password is required.");
}

installer.SetUserAccount(options.Account, options.Password);
}

installer.Context.Parameters.Add("assemblypath", GetType().Assembly.Location);

installer.Install(new Hashtable());
Expand Down
7 changes: 1 addition & 6 deletions Rhino.ServiceBus.Host/ExecutingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ExecutingOptions
[Argument(ArgumentType.Required, HelpText = "Service name", ShortName = "name")] public string Name;

[Argument(ArgumentType.AtMostOnce, LongName = "Account")] public string Account;
[Argument(ArgumentType.AtMostOnce, HelpText="Password for account used when installing service")]public string Password;

[Argument(ArgumentType.AtMostOnce, LongName = "Host")] public string Host;
[Argument(ArgumentType.AtMostOnce, LongName = "BootStrapper")] public string BootStrapper;
Expand All @@ -26,12 +27,6 @@ public override string ToString()
.Append(Name)
.Append("\"");

if(string.IsNullOrEmpty(Account)==false)
{
sb.Append(" /Account:")
.Append(Account);
}

if (string.IsNullOrEmpty(Host)==false)
{
sb.Append(" \"/Host:")
Expand Down
13 changes: 6 additions & 7 deletions Rhino.ServiceBus.Host/ProjectInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ public string ServiceName
}
}

public ServiceAccount Account
{
get
{
return serviceProcessInstaller1.Account;
}
}
public void SetUserAccount(string username, string password)
{
serviceProcessInstaller1.Account = ServiceAccount.User;
serviceProcessInstaller1.Username = username;
serviceProcessInstaller1.Password = password;
}

public ProjectInstaller()
{
Expand Down

0 comments on commit 8255b18

Please sign in to comment.