by Christophe via Christophe on 3/1/2009 6:47:58 PM
I had to install a Windows service on several servers this week (about 30 servers …). I wanted to do it using a simple batch file, and installing the service silently. Unfortunately, when using InstallUtil to install a Windows service, you can’t specify the credentials used by the service to logon. You can’t install your service with this kind of command line:
InstallUtil.exe MyService.exe /username=MyUserName /password=Password
[RunInstaller(true)]public partial class ProjectInstaller : Installer{ public ProjectInstaller() { InitializeComponent(); } public String GetContextParameter(String key) { if (this.Context == null || this.Context.Parameters == null || !this.Context.Parameters.ContainsKey(key)) return null; return this.Context.Parameters[key].ToString(); } protected override void OnBeforeInstall(IDictionary savedState) { base.OnBeforeInstall(savedState); String username = GetContextParameter("username"); String password = GetContextParameter("password"); if (!String.IsNullOrEmpty(username)) serviceProcessInstaller1.Username = username; if (!String.IsNullOrEmpty(password)) serviceProcessInstaller1.Password = password; }}
Original Post: Provide credentials (username and password) while installing a service silently
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.