0

I am writing a windows service that's supposed to act as a sort of "watchdog" for another, third-party application. This application is currently directly registered as a service (using sc create), but this makes updating difficult since I need to get an admin to stop the service, replace the binary, and then start it up again. So my intention was to build a wrapper service that periodically checks for updates and performs them if necessary (downloading the new file, stopping the application, and starting the new binary). I decided to try to use .NET Core's Worker Service template for this (using the Hosting extension to register them as a proper windows service), but I can't figure out how to actually start the 3rd-party application.

I was planning on just using Process.Start(<path-to-3rd-party-app>), but this gave me no results. After some digging, I found some old posts about how you can't directly start a Process from a windows service because of missing execution contexts or something in that vein (I am not very familiar with this stuff, this is my first attempt at writing a service), however the posts seemed to suggest that the problem essentially boils down to interactivity (can't open a window, etc.).

Finally, my question is this: Is there a way to start a 3rd-party application as a background process from a Windows Service in .NET Core? There is absolutely no need for interactivity of any kind, I just need the process to be running and me to be able to start it/stop it/specify arguments etc. from within my code.

Thank you!

EDIT: I forgot to add it when submitting, but the method used in this answer has not worked for me

EDIT 2: Some clarification, the 3rd-party app I'm trying to run spins up a web server/frontend. When I start the wrapper service directly from console (and also when the server itself was started directly as a service via sc.exe), I can access the web frontend without any issues. However, when I start my wrapper as a windows service, the web server never seems to start.

Grzzlwmpf
  • 11
  • 3
  • Why specifically interaction-less? Wouldn't you benefit from it logging potential exceptions? I understand you won't need to specifically require interaction, but it can at least display if necessary. – Reap Mar 24 '20 at 15:59
  • @Reap Well, the service itself has some logging routines, but since I don't specifically require the output of the 3rd-party app and other posts seemed to suggest that interactivity may be a problem I wated to clarify that I don't really need it – Grzzlwmpf Mar 24 '20 at 17:22
  • "but this gave me no results", what? Can you even see the process running? Make it very clear please, or others can guess nothing. – Lex Li Mar 24 '20 at 19:18
  • Windows has the concept of a _window station_. If your service is running in a different security concept compared to the interactive user it will connect to a new window station. This also applies to the process that you start. This might explain why it _gave no results_. https://learn.microsoft.com/en-us/windows/win32/winstation/window-station-and-desktop-creation – Martin Liversage Mar 25 '20 at 12:22

0 Answers0