Reputation: 9360
I am trying to make a windows service to start automatically before you are in a session.
I have tried using TopShelf
and adding the Start Automatically
method, but the service does not get started when i start the computer.I still have to start it manually.
Is there anything i am missing ?
Service Start
public static void RunService() {
var exitCode = HostFactory.Run(x => {
x.Service<SomeService>(s => {
s.ConstructUsing((h) => new SomeService());
s.WhenStarted(t => t.Start());
s.WhenStopped(t => t.Stop());
s.WhenSessionChanged((daemon, host, args) => daemon.SessionChanged(args.SessionId));
});
x.EnableSessionChanged();
x.EnableShutdown();
x.StartAutomatically();
x.RunAsLocalSystem();
});
int exitCodeValue = (int)Convert.ChangeType(exitCode, exitCode.GetTypeCode());
}
Upvotes: 1
Views: 1288
Reputation: 2433
See "Why doesn’t my Windows Service Start at Boot?" for additional advice.
Upvotes: 2