Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

TheboL.wwwxxxxx, WWWXXXAPC , wwwxxn.xsss, wwwxxxapc, WWWXXX.VCBA, wwwxxx vba, wwwxxxdoco, Wwwxxx.APC, wwwxxx CN2, can't locate in @inc (@inc contains



#1: Install Windows Service with Custom User Credentials

Posted on 2007-12-04 18:01:01 by B.Ahlstedt

Hi all,
This is something that I have been toying with for about a week now. What
I want to achieve is Install a Service with Customised parameters (using
InstallUtil.exe) for User Name. Example (C#);

public class MyServiceInstaller : System.Configuration.Install.Installer
private System.ServiceProcess.ServiceProcessInstaller
private System.ServiceProcess.ServiceInstaller serviceInstaller;

public MyServiceInstaller()
this.serviceProcessInstaller = new
this.serviceInstaller = new System.ServiceProcess.ServiceInstaller();

// Null out UserName and password
this.serviceProcessInstaller.Password = null;
this.serviceProcessInstaller.Username = null;
// this.serviceProcessInstaller.Account =

// Service Installer, set ServiceName to same as ServiceName in
ServiceBase derived class
this.serviceInstaller.ServiceName = "MyService";

// Add Both Installers to Project Installers Collection to be Run
this.Installers.AddRange(new System.Configuration.Install.Installer[] {

//POINT2 Override Install Method to add customised values
public override void Install(System.Collections.IDictionary stateSaver)
Console.WriteLine("Install Start...");

// Check for Custom User
if (this.Context.Parameters.ContainsKey("MyUserName") == true)
Console.WriteLine("******* Using CUSTOMISED values ....");
this.serviceProcessInstaller.Account =
this.serviceProcessInstaller.Password =
string user = this.Context.Parameters["MyUserName"];
string domain = this.Context.Parameters["MyDomainName"];

// Do we use Principal Name @ Authority or
Authority\Principal ( Domain\User )
string userName = string.Empty;
if (domain.IndexOf(".") > -1 && domain.Length > 1)
userName = string.Concat(user, "@", domain);
userName = string.Concat(domain, "\\", user);
// Update the Correct user Name
this.serviceProcessInstaller.Username = userName;
Console.WriteLine("******* Using HARDCODED values ....");
this.serviceProcessInstaller.Password = "password";
this.serviceProcessInstaller.Username = "DOMAIN\\User";
this.serviceProcessInstaller.Account =

Console.WriteLine("******* Username: {0}, Account: {1},
Password: {2}",

// Call the Base Class to finish Installation

Console.WriteLine("Install End...");

POINT1 - I have nulled the User Name and Password Fields and left the
Account Type as default in the MyServiceInstaller Constructor. I could
hard-code the values here, but that defeats the purpose of the exercise.

a) Running the command "InstallUtil MyService.exe" generates the following
Console Log (minus .NET. Framework Installation ...);
Install Start...
******* Using HARDCODED values ....
******* Username: DOMAIN\User, Account: User, Password: password
Install End...
b) Running the command "InstallUtil /MyUserName=User /MyDomainName=DOMAIN
/MyPassword=password MyService.exe" generates; (after Uninstall if above was
run first "InstallUtil /u MyService.exe")
Install Start...
******* Using CUSTOMISED values ....
******* Username: DOMAIN\User, Account: User, Password: password
Then Error Details;
An exception occurred during the Install phase.
System.ComponentModel.Win32Exception: The account name is invalid or does
not exist, or the password is invalid for the account name specified
at System.ServiceProcess.ServiceInstaller.Install(IDictionary stateSaver)
at System.Configuration.Install.Installer.Install(IDictionary stateSaver)
at TemplateService.TemplateServiceInstaller.Install(IDictionary
stateSaver) in
D:\Projects\Test\Services\TemplateService\TemplateServiceIns taller.cs:line 124
at System.Configuration.Install.Installer.Install(IDictionary stateSaver)
at System.Configuration.Install.AssemblyInstaller.Install(IDict ionary
at System.Configuration.Install.Installer.Install(IDictionary stateSaver)
at System.Configuration.Install.TransactedInstaller.Install(IDi ctionary

The Rollback phase of the installation is beginning.
See the contents of the log file for the
D:\Projects\Test\Services\TemplateService\bin\debug\Template Service.exe
assembly's progress.
The file is located at
D:\Projects\Test\Services\TemplateService\bin\debug\Template Service.InstallLog.

The Rollback phase completed successfully.

The transacted install has completed.

The machines that this occurs on are Windows XP Pro and XP Pro 64 (with
their respective x86 and x64 InstallUtil versions) and using .NET Framework
2.0, both connected to a Domain Controller. Changing the User Credentials to
a Local User, Domain Administrator still offers no difference, Hard coded
within Installer works, but using passed custom values to the Install Utility
seems to create some corruption on the install process.

This worked with InstallUtil in .NET v1.1 so am at a loss as to why
Hardcoding works but using the Context.Parameters StringDictionary creates
some kind of Error that InstallUtil cannot handle.

Anyone able to shed some light on this?

TIA Bjorn Ahlstedt

Report this message

#2: RE: Install Windows Service with Custom User Credentials

Posted on 2007-12-05 12:31:01 by BAhlstedt

In addition, if I comment out the whole Install override, the InstallUtil.exe
utility will provide the "Set Service Login" popup, and placing the *exact*
same DOMAIN\User and password combination as is Hard Coded or through the
Parameters, the installation completes successfully. This leads me to believe
that the problem lies with InstallUtil.exe and custom parameter handling.
Again this worked in the .NET v1.1 of the Framework but not on .NET v2.0 (x86
and x64).

Since the problem with InstallUtil.exe, I decided to test further, so I
added a Setup Project (right-click Solution -> Add... new Project -> Other
Project Types ... Setup and Deployment -> Setup Project) for my service. See
link ( for the general idea.

To work with my Installer and Install Override method, I had to add the
following to the Custom Actions -> Install -> Primary output ->
CustomActionData property;

Also I modified the Install Method slightly to handle better,
public override void Install(System.Collections.IDictionary stateSaver)
Console.WriteLine("Install Start...");

// Check for Custom User
if (this.Context.Parameters.ContainsKey("MyUserName") == true)

public override void Install(System.Collections.IDictionary stateSaver)
Console.WriteLine("Install Start...");

// Get the User name
string user = this.Context.Parameters["myUserName"];

// Check for Custom User
if (user != null && user.Length > 0)

Then installing using the command line;
'setupMSIname.msi' - installs fine - uses hardcoded values.
'setupMSIname.msi MyUserName="{user}" MyDomainName="{domain}"
MyPassword="{password}"' - where values in between { and } are the
appropriate values, also installs fine, but with the Custom Parameterised

Is there any reason why the InstallUtil.exe doesn't accept the user
credentials when passed as parameters from a batch file/command line, except
when run from a MSI Setup (if it does internally use the InstallUtil.exe)??

Hopefully I am missing something completely in which I can then humbly
accept and fix so that my InstallUtil.exe implementation works as required.


Report this message