ispiro
ispiro

Reputation: 27673

Will a startup Windows Service always run before a startup application?

I have a startup application that relies on a service (which also runs at startup). Will services always run first?

My goal is to know whether my application can assume that if the service is not running - it hasn't been installed (or some error has occurred) and the user should be notified or the service should be installed. If this is not necessarily true (that services run first), I would have the app wait some time and recheck before alerting the user or trying to install the service. (10 seconds? 2 minutes?)

EDIT

I am aware that a service might be intentionally not executed immediately (Delayed Start). I'm not referring to that.

More info: The service is mine as well. Installed by the app on first run asking the user for admin privileges. And the app is a UI app so can't run as a Service.

Upvotes: 2

Views: 1260

Answers (1)

Steve
Steve

Reputation: 11963

Will services always run first

Nope. definitely not. The service might took too long to start, or its dependency failed to start and it has to wait for that dependency to retry ect.

I have experienced this myself with the windows time service

However you have couple options for this

  1. Use task scheduler and set the trigger condition to "On an event" and figure out what Eventlog entry the particular service would generate on start.

  2. Make your application a service and declare that its depended on the service it requires. You will get an error stating the dependency is not met if the service is not installed.

  3. Allow the application to startup but checks every X seconds to make sure the service is up before continue.

Upvotes: 1

Related Questions