Share via


Service vs scheduled task

Question

Sunday, February 18, 2018 4:33 PM | 1 vote

Not sure if this is the best forum, but I didn't find any other obvious one.

I am working on a (headless) application which shall execute in the background on Windows 7 and above.
The application will work 24/7 listening for udp packets etc. so a scheduled task which is time triggered is out of the question.

The obvious initial choice was a Windows Service, but I have been looking at scheduled tasks and don't see much difference actually.

A scheduled task can (similar to service):
Run in isolated session 0.
Run at any account.
Automatically be restarted etc.

A Windows Service can:
Be managed by software easier(?) by "talking" to the Service Controller".
Service Controller adds events to Windows event log.
Dependencies and delayed start can be specified.

I guess it is correct to assume that writing a Windows Service is more work (and a bit harder to debug) than a console program which may be started as a scheduled task at boot (without any interactive session).

Is there some good general advice out there to help me for a good start?

All replies (8)

Monday, February 19, 2018 6:12 AM âś…Answered

I agree with your idea.

Crating or writing a service is much harder than creating a task scheduler, while both of them have the same effect on this case.

You could just create a task in task scheduler with a high permission for the app. It will start with login and run all the time.

Another way, computer startup script is worthwhile to try.

Regards

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Monday, February 19, 2018 7:33 AM

Yes, indeed. Writing a Windows Service should take more time. Using a task scheduler is much easier and a common option to use for most of the administrators as long as it fits their needs.

This posting is provided AS IS with no warranties or guarantees , and confers no rights.

Ahmed MALEK

My Website Link

My Linkedin Profile

My MVP Profile


Monday, February 19, 2018 8:45 AM | 1 vote

Yes, writing a native service will require more effort but you do receive a few ancillary benefits from a service:

  1. Error reporting: You can write errors and warnings to the Windows Event Log.
  2. Graceful stop/shutdown: Services have a well defined stop mechanism. As a scheduled task, your only option may be to terminate your application (from the Task Manager).
  3. Dependency configuration: Does your application rely on any system services? A scheduled task doesn't so there is the risk of it starting "too early".
  4. Command-line life-cycle management (local & remote): You can use the NET or SC commands to start/stop/check-status of a service. No good way to do that with a scheduled task.
  5. GUI life-cycle management (local & remote): Use the services.msc control panel application to start/stop/check-status of a service. No good way to do that with a scheduled task.
  6. Failure protection: Windows services can be configured to automatically restart when they fail (though not all types of failures may be eligible).

If none of those appeal to you, then you should probably go with a scheduled task!


Monday, February 19, 2018 12:29 PM

Thanks

What do you actually mean by "computer startup script"?
(Must be started in isolated session 0)


Monday, February 19, 2018 1:11 PM

Thanks Core Tech (nice name!)

Item1: Can't I write to Event Log from a console app ?(C# and .net 4.5 or higher)
Item6: I think similar can be achieved by task scheduler (Settings/Restart options)


Tuesday, February 27, 2018 9:54 AM

Open group policy editor and navigate to:

Computer Configuration\Windows settings\ Scripts (Startup/Shutdown).

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Tuesday, February 27, 2018 3:20 PM

Oh thanks, I didn't know about boot/shutdown script, only login/logout


Monday, March 5, 2018 9:19 AM

If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].