Using InstallUtil and silently setting up a username / password for Windows login

I need to use InstallUtil to install a C # Windows service. I need to set login credentials (username and password). All this needs to be done quietly.

Is there a way to do something like this:

installutil.exe myservice.exe /customarg1=username /customarg2=password 
+44
installer windows-installer windows-services
Sep 26 '08 at 15:01
source share
5 answers

Bravo to my colleague (Bruce Eddy). He found a way that we can make this call on the command line:

 installutil.exe /user=uname /password=pw myservice.exe 

This is done by overriding OnBeforeInstall in the installer class:

 namespace Test { [RunInstaller(true)] public class TestInstaller : Installer { private ServiceInstaller serviceInstaller; private ServiceProcessInstaller serviceProcessInstaller; public OregonDatabaseWinServiceInstaller() { serviceInstaller = new ServiceInstaller(); serviceInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic; serviceInstaller.ServiceName = "Test"; serviceInstaller.DisplayName = "Test Service"; serviceInstaller.Description = "Test"; serviceInstaller.StartType = ServiceStartMode.Automatic; Installers.Add(serviceInstaller); serviceProcessInstaller = new ServiceProcessInstaller(); serviceProcessInstaller.Account = ServiceAccount.User; Installers.Add(serviceProcessInstaller); } public string GetContextParameter(string key) { string sValue = ""; try { sValue = this.Context.Parameters[key].ToString(); } catch { sValue = ""; } return sValue; } // Override the 'OnBeforeInstall' method. protected override void OnBeforeInstall(IDictionary savedState) { base.OnBeforeInstall(savedState); string username = GetContextParameter("user").Trim(); string password = GetContextParameter("password").Trim(); if (username != "") serviceProcessInstaller.Username = username; if (password != "") serviceProcessInstaller.Password = password; } } } 
+50
Sep 26 '08 at 15:36
source share

A simpler way than the messages above and without additional code in your installer is this:

installUtil.exe / username = domain \ username / password = password / without access C: \ My.exe

Just make sure the account you are using is valid. If not, you will receive the message "No mapping between account names and security identifier."

+60
May 19 '10 at 8:54
source share

InstallUtil.exe installs StartupType = Manual

If you want autorun service, use:

sc config MyServiceName start= auto

(note that there must be space after the '=')

+5
Jul 02 '13 at 12:22
source share

No, installutil does not support this.

Of course, if you wrote the installer; with a custom action , you can use it as part of MSI or through installutil.

+3
Sep 26 '08 at 15:05
source share

You can also make your service run as a user using ServiceProcessInstaller :: Account = ServiceAccount.User ;

During installation, a pop-up window will appear asking for "[domain \] user, password".

 public class MyServiceInstaller : Installer { /// Public Constructor for WindowsServiceInstaller public MyServiceInstaller() { ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller(); ServiceInstaller serviceInstaller = new ServiceInstaller(); //# Service Account Information serviceProcessInstaller.Account = ServiceAccount.User; // and not LocalSystem; .... 
+3
Oct 23 '09 at 14:31
source share



All Articles