The Core Technologies Blog

Our Software // Windows Services // 24×7 Operation


Q&A: How Do I Delay the Start of my Windows Service?

Q&A: How Do I Delay the Start of my Windows Service?
  Our build server has a ton of services installed and it takes a while for them to start whenever the machine boots. One of the services doesn’t connect to the database if it starts too soon. When that happens, I have to log in and start it manually. Is there a way to delay the service until the other services are up and running?

— Christos D.

Hi Christos.

After some brainstorming, our team has come up with four potential solutions for you.

Solution #1: Set your Service to “Automatic (Delayed Start)”

The simplest way to delay a service is to adjust when it starts at boot. Instead of starting as soon as possible, you can tell Windows to launch the service about 2 (or more) minutes after boot.

To make that change:

  1. Start the Services utility.

    To do so, press the Windows + R keys to open the Run window, and then type services.msc.

  2. Find your service in the list. Double-click its row to open the service’s properties.

  3. In the Startup type field, select Automatic (Delayed Start) from the list:

    Choose Automatic (Delayed Start)
  4. Click OK to save your change.

Need to wait for longer than 2 minutes?

By default, all “delayed start” services are launched a couple of minutes after boot. Fortunately, that wait time is configurable and you can set it to longer if you like, but that setting applies to all delayed start services. There is simply no way to adjust the wait time of a single delayed start service.

Solution #2: Specify a Dependency between Services

Another option for delaying the start of a service is to mark it as dependent on another service.

To explain, let’s take two services, Service1 and Service2. If Service1 must start before Service2, you would update Service2 to add Service1 as a dependent. You would say that Service2 depends on Service1.

I know that may be a bit confusing, so let’s look at a real-world example.

Microsoft’s “System Events Broker” depends on a couple of services: “Remote Procedure Call (RPC)” and “RPC Endpoint Mapper”. You can see the relationship in the service’s properties (in the Services application):

System Events Broker service: Dependencies

Because of those dependencies, Windows will always start the two RPC services before launching the “System Events Broker” service.

So to delay the start of your important service, mark it as dependent on another, precursor service.

Note however, there are significant side effects of setting up a dependency relationship between two services.

For example, the screenshot above also shows that “Task Scheduler” depends on “System Events Broker”. As a result of that relationship, stopping “System Events Broker” will stop “Task Scheduler”, as the Services application informs us here:

Stop the System Events Broker service

You see, the dependency relationship is about much more startup sequence. It implies that “System Events Broker” is critical for “Task Scheduler” to operate.

So if you mark your service as dependent on another service, stopping that other service might stop your own. Make sure you’re OK with that.

Solution #3: Launch your service from an “at startup” scheduled task

Instead of having the Windows Services launch your service, you can shift that responsibility to the Windows Task Scheduler. And in doing so, you can introduce a post-boot delay to start the service after your machine settles down.

Here’s how to create a scheduled task that starts your service a few minutes after boot:

  1. Launch the Task Scheduler.

    To do so, press the Windows + R keys to open the Run window, and then type taskschd.msc.

  2. On the right, click Create Basic Task to launch the wizard:

    Task Scheduler: Create Basic Task
  3. Give your task a meaningful name. For example, we’re restarting the Print Spooler service 10 minutes after boot:

    Start Spooler service task: Name

    Click Next.

  4. For the trigger, choose When the computer starts:

    Start Spooler service task: Trigger

    Click Next.

  5. For action, select Start a program:

    Start Spooler service task: Action

    Click Next.

  6. In the Program/script field, enter NET.EXE.

    And in the Add arguments field, enter START followed by the name of your service:

    Start Spooler service task: Run NET START

    Click Next.

  7. On the summary screen, check the Open the Properties dialog… box. We still need to make a few adjustments to the new scheduled task:

    Start Spooler service task: Summary

    Click Finish to exit the wizard.

  8. In the Properties window that comes up, affirm a couple of options:

    Run whether user is logged on or not. Otherwise, your service will only restart when you’re logged on.

    Run with highest privileges. Necessary because starting your service likely requires administrative rights.

    Start Spooler service task: Properties
  9. Switch to the Triggers tab and edit the At startup trigger.

    In the Edit Trigger window, check the Delay task for box and enter your delay in minutes. You may have to type the time as not all values appear in the dropdown:

    Start Spooler service task: Edit Trigger

    Click OK to save your change.

  10. Back on the Properties window, click OK to close out of the task. You will probably have to enter your password:

    Start Spooler service task: Enter password

And now that you have a scheduled task to start the service when you want, you should prevent the service from trying to start automatically at boot. Open your service’s properties and change the Startup type to Manual:

Set service startup type to Manual

Finally, please reboot and make sure that your service starts in the expected time frame.

Solution #4 (for AlwaysUp services only): Pause before starting

If your service was created by AlwaysUp, you are able to stall your application via a configuration setting.

To do so:

  1. Edit your application in AlwaysUp.

  2. Switch to the Startup tab.

  3. In the Pause for field, enter a suitable delay in seconds:

    Set AlwaysUp startup pause time
  4. Check the But only after a reboot box — to avoid the pause when you start the service/application manually.

  5. Click OK to save your settings.

The next time your computer boots, Windows will start the AlwaysUp service. And, as you instructed, AlwaysUp will pause for a while before launching your application.

Hopefully one of these methods will work in your situation!

Posted in Windows Services | Tagged , , , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *