Grzenio Grzenio - 21 days ago 6
C# Question

ServiceProcessInstaller fails with "No mapping between account names and security IDs was done"

I have an installer class using

ServiceProcessInstaller
. In the installer class in the constructor I add it to installers:

serviceProcessInstaller = new ServiceProcessInstaller();
serviceInstaller = new ServiceInstaller();

// Add Both Installers to Project Installers Collection to be Run
Installers.AddRange(new Installer[]
{
serviceProcessInstaller,
serviceInstaller
});


and in Install method I set the username and password:

public override void Install(IDictionary stateSaver)
{
.... open the form, bla bla bla
serviceProcessInstaller.Password = accountForm.txtPassword.Text;
serviceProcessInstaller.Username = accountForm.txtServiceAccount.Text;
serviceProcessInstaller.Account = ServiceAccount.User;
}


when I try to run it however, I get the very descriptive error message: "No mapping between account names and security IDs was done". What am I doing wrong?

EDIT: I tested that this error happens only when I install this component using msi package. It works just fine when I run InstallUtil against it.

Answer

Found it finally: there seems to be a "feature" in ServiceProcessInstaller, where the code overwrites the values I provided explicitly with the values from the context. The MSI installer set the username to some crap (my company name), and ServiceProcessInstaller tried to install the service as this user and not the one explicitly provided by me. So the workaround is to set the correct values in the config:

public override void Install(IDictionary stateSaver)
{
    .... open the form, bla bla bla
    serviceProcessInstaller.Password = accountForm.txtPassword.Text;
    Context.Parameters["PASSWORD"] = accountForm.txtPassword.Text;
    serviceProcessInstaller.Username = accountForm.txtServiceAccount.Text;
    Context.Parameters["USERNAME"] = accountForm.txtServiceAccount.Text;
    serviceProcessInstaller.Account = ServiceAccount.User;
}
Comments