Question

I'm trying to install a .NET service I wrote. As recommended by MSDN, I'm using InstallUtil. But I have missed how I can set the default service user on the command-line or even in the service itself. Now, when InstallUtil is run, it will display a dialog asking the user for the credentials for a user. I'm trying to integrate the service installation into a larger install and need the service installation to remain silent.

Was it helpful?

Solution

I think I may have found it. In the service itself, the automatically created ServiceProcessInstaller component has a property "Account" which can be set to "LocalService", "LocalSystem", "NetworkService" or "User". It was defaulting to "User" which must have displayed the prompt.

OTHER TIPS

As you noticed, Karim, "Account" property is the solution, here. For those interested in differences between security contexts set by this property:

http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceaccount.aspx

Above using InstallUtil or SC, I like the idea of creating a SELF INSTALLER:

http://www.codeproject.com/KB/dotnet/WinSvcSelfInstaller.aspx

even though I found this in the .Net 1.1 documentation:

The ManagedInstallerClass type supports the .NET Framework infrastructure and is not intended to be used directly from your code.

Also keep in mind the SC.exe util which does not require visual studio to be installed. You can simply copy this exe to the server you want to create the service or even run it remotely. Use the obj parameter to specify a user.

Apparently there is a GUI for this tool, but I have not used it.

Are you being asked for the account to run the service under, or for rights to install the service? For the second, installing as admin should prevent that from happening. For the first, you have to add a ServiceProcessInstaller to your Installer.

I believe the design surface for a service has a link to create a Project Installer. On that designer, you can add a process installer of type System.ServiceProcess.ServiceProcessInstaller. The properties of this object allow you to set the account to use for the service.

InstallUtil has command line switches which can avoid the prompts when using "User" as the account type. /username and /password are used configure the account at install time.

Usage:

installutil.exe /username=user /password=password yourservice.exe

What you may want is to have a config file where the installer can read and install the service.

To do so, add a service installer to your project, and overload the install method. In this method, set the username and password:

public override void Install(IDictionary stateSaver)
{
    serviceProcessInstaller1.Username="<username>";
    serviceProcessInstaller1.Password="<password>";
    base.Install(stateSaver);
}

If you try to set the username and password in the constructor, those values will be overwritten, so make sure you override "Install" to do so.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top