1

To be more precise, this is a failsafe that I am trying to create for my windows service. For information, I need my windows service to extract data from a server at 15mins intervals everyday. E.g., 12:00am, 12:15am, 12:30am, 12:45am, 1am... Hence, if my PC shuts down at 3.04pm and reboots and 3.05pm, I need my task scheduler to only restart the windows service at 3:15pm. If my PC shuts down and reboots at 3:25pm, I need my task scheduler to only start the windows service at 3.30pm. The task scheduler must run the windows service only once no matter the hour, at the __:00/15/30/45mins mark depending on when the PC reboots.

Previously, I have set the task scheduler "on a schedule" to restart the windows service at 15mins interval starting at 12am everyday. However, this causes a break in the data collected from server 1 and sent to server 2. Hence, I only need my task scheduler to execute the windows service "at startup". How am I able to do this? Any help is appreciated.

1 Answer 1

0

Windows services can have a delayed startup set via the Services applet, but this by default only delays the execution by 2 minutes.

You may set this delay to 15 minutes, with the disadvantage that all system services that are defined with delayed start will then start after 15 minutes, rather than 2 minutes. This is done in registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control, DWORD item AutoStartDelay, counted in milliseconds.


To avoid this inconvenience requires a more complex solution:

You need to use the Task Scheduler to run a task after startup, with 15 minutes delay, which will enable your service using the sc config command.

You also need to create a shutdown script to disable the service. See
Run a script just before shutdown or reboot on Windows Home edition.

6
  • 1
    Appreciate the reply! However, I do not want to set the delay to be exactly 15mins. It has to be flexible depending on when my PC reboots. I want it to start at the nearest 15mins mark instead. so __:00/15/30/45 am/pm. I read that I need to find the entry point/source code for my windows service, and edit the code to find the current time and calculate the delay. However, what if I do not have access to the entry point/source code, is it still possible to do implement this function?
    – Wyap005
    Commented Nov 20, 2023 at 7:01
  • My answer has two parts (I added a divider to highlight it). The second part should work for you (I agree that the first part might be too sweeping).
    – harrymc
    Commented Nov 20, 2023 at 8:06
  • Thank you for that, and I have tried it on the task scheduler, but the delay is fixed to 15mins, which is not what I require. I need my windows service to run at every quarter hour mark. Hence, I need to find out the current time, calculate the delay to the nearest quarter hour mark (00/15/30/45mins) and then execute my windows service after the delay. I managed to do it through running a powershell script on task scheduler to do the work.
    – Wyap005
    Commented Nov 22, 2023 at 2:05
  • Task Scheduler can repeat the task every 15 minutes. Does your service terminate immediately? Why use a service in this case?
    – harrymc
    Commented Nov 22, 2023 at 8:59
  • Running the task scheduler every 15mins to start and stop my service causes data loss for my service. Hence I had to find an alternative.
    – Wyap005
    Commented Nov 27, 2023 at 6:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .