When you open the Service COntrol Manager,(SCM), of course,there is a tab labeled Logon.. In there you can specify which domain or machine account it should run under...
But programatically. if you use a Service Installer class in your code you can specify it there..
public class MyServiceInstaller : Installer
{
private ServiceInstaller servInst;
private ServiceProcessInstaller servProcInst;
public MyServiceInstaller () { InitializeComponent(); }
#region Component Designer generated code
private void InitializeComponent()
{
servInst = new ServiceInstaller();
servProcInst = new ServiceProcessInstaller();
// -----------------------------------------------
servProcInst.Account = ServiceAccount.LocalSystem; // or whatever accnt you want
servProcInst.Username = null; // or, specify a specifc acct here
servProcInst.Password = null;
servProcInst.AfterInstall +=
new InstallEventHandler(this.AfterServProcInstall);
servInst.ServiceName = "MyService";
servInst.DisplayName = "Display name for MyService";
servInst.Description = " Description for my service";
servInst.StartType = ServiceStartMode.Automatic;
servInst.AfterInstall +=
new InstallEventHandler(this.AfterServiceInstall);
Installers.AddRange(new Installer[] { servProcInst, servInst });
}
#endregion
}
private void AfterServiceInstall(object sender, InstallEventArgs e) { }
private void AfterServProcInstall(object sender, InstallEventArgs e) { }