1

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

Penguen
  • 16,836
  • 42
  • 130
  • 205
  • 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 Answers6

6

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
  • 80,725
  • 18
  • 167
  • 237
1

Set the startup type to "Automatic".

David Neale
  • 16,498
  • 6
  • 59
  • 85
0

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

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • 3
    actually it is - installer programming. – TomTom May 11 '10 at 12:51
  • @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
0

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

TomTom
  • 61,059
  • 10
  • 88
  • 148
0

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
  • 7,482
  • 10
  • 66
  • 120
0

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.

Kevin Kibler
  • 13,357
  • 8
  • 38
  • 61