Skip to content

Commit

Permalink
fixed Topshelf#320 added support for group managed service accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Winningham authored and TravisTheTechie committed Oct 13, 2016
1 parent 6320b81 commit 1ecd70e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Topshelf/Runtime/Windows/WindowsHostEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,25 @@ public void InstallService(InstallHostSettings settings, Action<InstallHostSetti
{
beforeInstall(settings);
installer.ServiceProcessInstaller.Username = settings.Credentials.Username;
installer.ServiceProcessInstaller.Password = settings.Credentials.Password;
installer.ServiceProcessInstaller.Account = settings.Credentials.Account;

// Group Managed Service Account (gMSA) workaround per
// https://connect.microsoft.com/VisualStudio/feedback/details/795196/service-process-installer-should-support-virtual-service-accounts
if (settings.Credentials.Account == ServiceAccount.User &&
settings.Credentials.Username != null &&
settings.Credentials.Username.EndsWith("$", StringComparison.InvariantCulture))
{
_log.InfoFormat("Installing as gMSA {0}.", settings.Credentials.Username);
installer.ServiceProcessInstaller.Password = null;
installer.ServiceProcessInstaller
.GetType()
.GetField("haveLoginInfo", BindingFlags.Instance | BindingFlags.NonPublic)
.SetValue(installer.ServiceProcessInstaller, true);
}
else
{
installer.ServiceProcessInstaller.Password = settings.Credentials.Password;
}
}
};

Expand Down

0 comments on commit 1ecd70e

Please sign in to comment.