How to auto start window service
Asked Answered
T

2

7

I have a window service which i developed in c# (vs2008). please tell me what should i do to make it auto start after installation and also auto start on every time when system gets restarted.

EDIT: I am using setup & deployment project to install it. Thanks

Tricot answered 17/12, 2010 at 6:5 Comment(2)
How do you install your service?Jadajadd
@Albin: i am using setup & deployment project to install it.Tricot
F
10

Follow the instructions given here to add an installer to your Service application. Pay particular attention to step 5, where you set the StartType property.

To start the service after installation, see Automatically start a Windows Service on install

Flasher answered 17/12, 2010 at 6:8 Comment(3)
#Jay: not able to find 'StartType' property. please tell me more about itTricot
its for installer class, but i am using setup and deployment project.Tricot
@Rajesh: I edited. You'll need to add an installer to your Service application - you can set use your Setup & Deployment project however.Flasher
G
2

Try following way,

private void serviceInstaller_AfterInstall(object sender, InstallEventArgs e)
        {
            var service = new ServiceController(serviceInstaller.ServiceName);
            if (service.Status != ServiceControllerStatus.Running)
            {
                service.Start();
            }
        }
Geest answered 20/2, 2015 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.