简体   繁体   中英

Launch an exe application from windows service

I have a service which should open an exe application ( C# Application ) based on certain conditions. When the service is started in debugging mode ( Visual studio ) it opens the application. But when it is installed as a service, it does not do so. It fails to open the application. Why is this happening?

What you're trying to do isn't directly possible under normal circumstances - simply launching an app in a new process from your Windows Service code is not going to interact with the GUI of the currently logged in user I'm afraid.

There are ways of communicating between a service and the GUI however.

This discussion might point you in the right direction .

Based on your comments, I think what you are really looking for here is a normal userspace application and a scheduler. You might want to use Windows' own scheduler to run the application every monday, if it is an always-on box, or place the application in Startup. When the application runs, it should check the current day of week, and if it is monday and the application has not previously run this day, the application should start. If not, you can safely terminate the application entirely.

Thanks for the answers! I found out a solution for it and im posting it here. I created a dummy app which is hidden on startup and it does the exact same function that the service was intended to.

1.create a dummy app (copy paste code from service to form application) Hide it after start up. 2.start the application right after installation. 3.add registry key so that it starts up after a system reboot.

in simple words, clone service behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM