i try to develop a windows service. My win service must run if windows 7 stars up. How can i do?
-
possible duplicate of [Automatically start a Windows Service on install](http://stackoverflow.com/questions/1036713/automatically-start-a-windows-service-on-install) – ChrisF May 11 '10 at 12:51
-
Please ignore my vote to close - I had the wrong question link on the clipboard. – ChrisF May 11 '10 at 12:52
6 Answers
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
- 80,725
- 18
- 167
- 237
You set service startup to "Automatic" in service control manager. Not a programming question, by the way.
- 59,826
- 25
- 160
- 281
-
3
-
@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 May 11 '10 at 13:09
Actually make sure your installer sets the startup type on Automatic ;) Add dependencies as needed so that you start after dependent services.
- 61,059
- 10
- 88
- 148
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.
- 7,482
- 10
- 66
- 120
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.
- 13,357
- 8
- 38
- 61