<p>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.</p>

[{'answer_id': 32196, 'author': 'Karim', 'author_id': 2494, 'author_profile': 'https://Stackoverflow.com/users/2494', 'pm_score': 7, 'selected': True, 'text': '<p>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.  </p>\n'}, {'answer_id': 32202, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>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.</p>\n\n<p>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.</p>\n'}, {'answer_id': 54317, 'author': 'Craig Tyler', 'author_id': 5408, 'author_profile': 'https://Stackoverflow.com/users/5408', 'pm_score': 2, 'selected': False, 'text': '<p>Also keep in mind the <strong><a href="http://support.microsoft.com/?kbid=251192" rel="nofollow noreferrer">SC.exe util</a></strong> 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 <strong>run it remotely</strong>. Use the <strong>obj</strong> parameter to specify a user.</p>\n\n<p>Apparently there is a GUI for this tool, but I have not used it.</p>\n'}, {'answer_id': 1140723, 'author': 'Aoi Karasu', 'author_id': 138255, 'author_profile': 'https://Stackoverflow.com/users/138255', 'pm_score': 2, 'selected': False, 'text': '<p>As you noticed, Karim, "Account" property is the solution, here. For those interested in differences between security contexts set by this property:</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceaccount.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceaccount.aspx</a></p>\n\n<p>Above using InstallUtil or SC, I like the idea of creating a <strong>SELF INSTALLER</strong>:</p>\n\n<p><a href="http://www.codeproject.com/KB/dotnet/WinSvcSelfInstaller.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/dotnet/WinSvcSelfInstaller.aspx</a></p>\n\n<p>even though I found this in the .Net 1.1 documentation:</p>\n\n<blockquote>\n  <p>The <strong>ManagedInstallerClass</strong> type\n  supports the .NET Framework\n  infrastructure and is not intended to\n  be used directly from your code.</p>\n</blockquote>\n'}, {'answer_id': 50661256, 'author': 'D. Lockett', 'author_id': 7716585, 'author_profile': 'https://Stackoverflow.com/users/7716585', 'pm_score': 0, 'selected': False, 'text': '<p>InstallUtil has command line switches which can avoid the prompts when using "User" as the account type. <code>/username</code> and <code>/password</code> are used configure the account at install time.</p>\n\n<p>Usage:</p>\n\n<pre><code>installutil.exe /username=user /password=password yourservice.exe\n</code></pre>\n\n<p>What you may want is to have a config file where the installer can read and install the service.</p>\n\n<p>To do so, add a service installer to your project, and overload the install method.  In this method, set the username and password:</p>\n\n<pre><code>public override void Install(IDictionary stateSaver)\n{\n    serviceProcessInstaller1.Username="&lt;username&gt;";\n    serviceProcessInstaller1.Password="&lt;password&gt;";\n    base.Install(stateSaver);\n}\n</code></pre>\n\n<p>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.</p>\n'}]
['https://Stackoverflow.com/questions/32175', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2494/']