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.
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.
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.
@Will: Yeah, I'm referring to the account to run the service under. And yeah, the ServiceProcessInstaller was already there but I hadn't seen that property you mentioned until shortly after I wrote my question. Sigh.
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.
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.