views:

88

answers:

6

i try to develop a windows service. My win service must run if windows 7 stars up. How can i do?

+5  A: 

Change the startup type of the service to Automatic.

You should create an installer application for your service (if you haven't already) and you can set this option in there so when its installed it is pre-configured this way. See Walkthrough: Creating a Windows Service Application in the Component Designer

James
First one in gets the point. :)
David M
A: 

You set service startup to "Automatic" in service control manager. Not a programming question, by the way.

Seva Alekseyev
actually it is - installer programming.
TomTom
@TomTom: Although the question has been *viewed* as an installer programming question, the OP doesn't actually mention anything about it which is why @Seva probably assumed he was referring to doing this via the service console.
James
+1  A: 

Set the startup type to "Automatic".

David Neale
A: 

Actually make sure your installer sets the startup type on Automatic ;) Add dependencies as needed so that you start after dependent services.

TomTom
A: 

If you want to set this programmatically (i.e. during the development phase) then this is set in the properties for the Installer (StartType), which you will also need.

awj
A: 

You could configure the service through the command line using the "SC" utility provided by Windows; it comes with XP and later.

sc create MyServiceName binPath= <path to service exe file> start= auto DisplayName= MyServiceDisplayName

sc description MyServiceName "This is my service's description"

The spaces after arguments (like binPath= ) are important.

CodeSavvyGeek