3

My Situation

I work for a company that builds software for many other companies. When I learned installers weren't built-in with VS2012, I was curious how to deploy. So far, I have just been dropping .exes on our clients servers using PowerShell scripts. Now I need a full-blown Windows service.

I have seen many example of how to run services via a console application: https://stackoverflow.com/questions/7764088/net-console-application-as-windows-service

I could easily use sc.exe to create a service based on a console application like this. I have no idea how Windows would handle Start/Stop/Restart, though.

The Question

This has made me curious what the relationship between console applications and services is in the Window's world. Are services just console applications with hooks to allow the OS to call start and stop? Or are services completely different?

A long time ago, I thought WinForms and console applications were completely different. After messing around in Win32, I realized they were the same thing.

My Hopes

I am hoping services are just console apps, like WinForms, and that I can tap into the Start/Stop capabilities directly in .NET. The built-in installer projects were pretty awful, so I don't feel too bad for copying .exes to the server.

6

I wouldn't say that a console application is totally different from a windows service. They are both hosts to execute code. That being said, there are some key differences:

  • A service can run even if a user is not logged into the PC.
  • A service can easily be configured to run in the context of a high-authority accounts such as Network Service or Local System.
  • A service comes built in with hooks for starting, stopping, restarting, and pausing while running.
  • A service doesn't have an attached console, it can't print anything to stdout but has to use system logging instead (credit to Martin)
  • 3
    A service doesn't have an attached console, it can't print anything to stdout but has to use system logging instead – Martin Beckett Nov 20 '13 at 3:39
  • Excellent point, added to main post. – Nathan Nov 20 '13 at 19:57
  • "A service can can easily be configured to run in the context of a high-authority accounts such as Network Service or Local System." -- not quite, I can schedule tasks to have console apps run as all of these pretty easily. I wouldn't call Network Service high authority either. – Wyatt Barnett Nov 20 '13 at 21:57
  • All of the benefits you mentioned would be easily applicable to Console Applications. The only benefit that is there is for a user to be logged in. – Saeed Neamati Jun 17 '15 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.