Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting a windows application from a windows service

I am trying to start a windows application from a windows Service using the below code

Process.Start(@"filename.exe");

In windows 7 I receive a popup that says, "A program running on this computer is trying to display a message"

like image 544
Ghyath Serhal Avatar asked Dec 09 '10 13:12

Ghyath Serhal


People also ask

Can a Windows Service start an application?

Windows Services cannot start additional applications because they are not running in the context of any particular user. Unlike regular Windows applications, services are now run in an isolated session and are prohibited from interacting with a user or the desktop. This leaves no place for the application to be run.

Can a Windows Service have an API?

Web API is fully capable of being self hosted on top of OWIN, and does not require IIS to run. Web API self hosted is basically just a console app. So the techniques for turning a Web API console app into a Windows Service are the same as for any other . NET console app.


3 Answers

You cannot start an interactive application from a Windows Service. This was changed in Windows Vista and 7.

Some other advice was given in this Stack Overflow answer on the same subject.

When I've needed to do this, I had to change my Windows Service to a Console Application, and invoked it in that manner.

like image 148
George Stocker Avatar answered Nov 01 '22 08:11

George Stocker


A work-around I found for this issue was to use the windows task scheduler. You can schedule the application to run some amount of seconds later by creating a batch file.

like image 44
Andrew Avatar answered Nov 01 '22 06:11

Andrew


At my previous company we had this issue and we wrote a console app that ran in the sys tray and acted as a bridge from the service to the desktop. Basically via remoting (I'd use WCF now of course) we let the service request that the console app start up another application.

like image 1
juharr Avatar answered Nov 01 '22 08:11

juharr