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.