473,545 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Install Windows Service with Custom User Credentials

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#);

[RunInstaller(tr ue)]
public class MyServiceInstal ler : System.Configur ation.Install.I nstaller
{
private System.ServiceP rocess.ServiceP rocessInstaller
serviceProcessI nstaller;
private System.ServiceP rocess.ServiceI nstaller serviceInstalle r;

public MyServiceInstal ler()
{
this.servicePro cessInstaller = new
System.ServiceP rocess.ServiceP rocessInstaller ();
this.serviceIns taller = new System.ServiceP rocess.ServiceI nstaller();

// Null out UserName and password
//POINT1
this.servicePro cessInstaller.P assword = null;
this.servicePro cessInstaller.U sername = null;
// this.servicePro cessInstaller.A ccount =
System.ServiceP rocess.ServiceA ccount.User;

// Service Installer, set ServiceName to same as ServiceName in
ServiceBase derived class
this.serviceIns taller.ServiceN ame = "MyService" ;

// Add Both Installers to Project Installers Collection to be Run
this.Installers .AddRange(new System.Configur ation.Install.I nstaller[] {
this.servicePro cessInstaller,
this.serviceIns taller});
}

//POINT2 Override Install Method to add customised values
public override void Install(System. Collections.IDi ctionary stateSaver)
{
Console.WriteLi ne("Install Start...");

// Check for Custom User
if (this.Context.P arameters.Conta insKey("MyUserN ame") == true)
{
Console.WriteLi ne("******* Using CUSTOMISED values ....");
this.servicePro cessInstaller.A ccount =
System.ServiceP rocess.ServiceA ccount.User;
this.servicePro cessInstaller.P assword =
this.Context.Pa rameters["MyPassword "];
string user = this.Context.Pa rameters["MyUserName "];
string domain = this.Context.Pa rameters["MyDomainNa me"];

// Do we use Principal Name @ Authority or
Authority\Princ ipal ( Domain\User )
string userName = string.Empty;
if (domain.IndexOf (".") -1 && domain.Length 1)
{
userName = string.Concat(u ser, "@", domain);
}
else
{
userName = string.Concat(d omain, "\\", user);
}
// Update the Correct user Name
this.servicePro cessInstaller.U sername = userName;
}
else
{
Console.WriteLi ne("******* Using HARDCODED values ....");
this.servicePro cessInstaller.P assword = "password";
this.servicePro cessInstaller.U sername = "DOMAIN\\Us er";
this.servicePro cessInstaller.A ccount =
System.ServiceP rocess.ServiceA ccount.User;
}

Console.WriteLi ne("******* Username: {0}, Account: {1},
Password: {2}",
this.servicePro cessInstaller.U sername,
this.servicePro cessInstaller.A ccount,
this.servicePro cessInstaller.P assword);

// Call the Base Class to finish Installation
base.Install(st ateSaver);

Console.WriteLi ne("Install End...");
}
}

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

POINT2 -
a) Running the command "InstallUti l 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 "InstallUti l /MyUserName=User /MyDomainName=DO MAIN
/MyPassword=pass word MyService.exe" generates; (after Uninstall if above was
run first "InstallUti l /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.Componen tModel.Win32Exc eption: The account name is invalid or does
not exist, or the password is invalid for the account name specified
at System.ServiceP rocess.ServiceI nstaller.Instal l(IDictionary stateSaver)
at System.Configur ation.Install.I nstaller.Instal l(IDictionary stateSaver)
at TemplateService .TemplateServic eInstaller.Inst all(IDictionary
stateSaver) in
D:\Projects\Tes t\Services\Temp lateService\Tem plateServiceIns taller.cs:line 124
at System.Configur ation.Install.I nstaller.Instal l(IDictionary stateSaver)
at System.Configur ation.Install.A ssemblyInstalle r.Install(IDict ionary
savedState)
at System.Configur ation.Install.I nstaller.Instal l(IDictionary stateSaver)
at System.Configur ation.Install.T ransactedInstal ler.Install(IDi ctionary
savedState)

The Rollback phase of the installation is beginning.
See the contents of the log file for the
D:\Projects\Tes t\Services\Temp lateService\bin \debug\Template Service.exe
assembly's progress.
The file is located at
D:\Projects\Tes t\Services\Temp lateService\bin \debug\Template Service.Install Log.

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.Paramet ers StringDictionar y creates
some kind of Error that InstallUtil cannot handle.

Anyone able to shed some light on this?

TIA Bjorn Ahlstedt
Dec 4 '07 #1
1 20346
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 (http://support.microsoft.com/kb/816169) 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 ->
CustomActionDat a property;
"/MyUserName=[MYUSERNAME] /MyDomainName=[MYDOMAINNAME]
/MyPassword=[MYPASSWORD]".

Also I modified the Install Method slightly to handle better,
from:
public override void Install(System. Collections.IDi ctionary stateSaver)
{
Console.WriteLi ne("Install Start...");

// Check for Custom User
if (this.Context.P arameters.Conta insKey("MyUserN ame") == true)

to:
public override void Install(System. Collections.IDi ctionary stateSaver)
{
Console.WriteLi ne("Install Start...");

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

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

Then installing using the command line;
'setupMSIname.m si' - installs fine - uses hardcoded values.
or
'setupMSIname.m si MyUserName="{us er}" MyDomainName="{ domain}"
MyPassword="{pa ssword}"' - where values in between { and } are the
appropriate values, also installs fine, but with the Custom Parameterised
values.

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.

TIA
Dec 5 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1502
by: Marina | last post by:
Hi, The windows service has reference to some custom DLL's, which are located in "subfolder/anotherfolder" relative to the service exe. There is a configuration file for the .exe which specifies to add "subfolder/anotherfolder" as a path to search for dll's needed for the project. However, during the install, this configuration file is...
1
5091
by: csheng | last post by:
I have a application to deliver now, and I am stuck. I developed a windows service, and I use intallutil to install. It works fine in development machine, when I copy the file to a windows 2003 server, i got the following error, what is causing this? Thanks for help in advance. Installing assembly 'c:\ewsconnector\ewsconnector.exe'....
0
1628
by: MarkM | last post by:
Hi there. Since upgrading to XP SP2 on my development box, I now compile the same windows service code and try to install it on a Windows 2000 server. Throws error "Access Is Denied". The installer then backs out and says the "The installer was interrupted before the service could be installed". I have installed this same service on...
2
1855
by: Ant | last post by:
Does anyone have an example of how to install a windows service from .net code. I've seen PInvoke versions, but it should be able to be done using System.Configuration.Install.Installer as the InstallUtil does. Thanks
2
11874
by: Shani | last post by:
Could someone suggest me as to how to install an Windows Service in C#? I do not want to use InstallUtil as I need to pass a parameter, which is not possible. I do not want to use write an installer application either. I want to install from Command Line prompt from .NET and pass in different parameter values hsomething like, ServiceName...
3
56938
by: Jeremy S. | last post by:
On my dev machine (XP/Pro with VS.NET 2003) I have been developing a Windows Service and installing it on the local machine by opening the Visual Studio Command Prompt and then executing . Now I want to test this service on a Windows Server 2003 box that doesn't have the Visual Studio Command prompt. How do I go about installing the...
8
5369
by: Stanley | last post by:
I have finished a Windows Service, now I'm trying to deploy the service to all my local computers. I want to ask if there is a fast way, rather then install it one by one? All answer would be highly appreciated! Thanks! Best regards, Stanley
3
15466
by: =?Utf-8?B?Um9iZXJ0IFNsYW5leQ==?= | last post by:
I'm trying to install a .NET Windows Service using the ServiceInstaller / ServiceProcessInstaller classes. I cannot seem to find a way to specify command line arguments. I've looked through ServiceInstaller:Install method using reflector and it appears that it is not possible. According to the Win32 doco, the CreateService function in...
0
1140
by: crowl | last post by:
Following scenario: client (c# app) -asp.net web service - sql server The client hast to authenticated via Basic authentications. This user account should be used to access the sql server on another machine. Is this possible? The web servcie uses integrated security=SSPI; for connecting to sql server, however, it seems to use anonymous...
0
7459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7653
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7803
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7411
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7749
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5322
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4942
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.