Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a dialog window from a windows service

I have created a windows service application in C# to popup a dialog window at particular intervals. While debugging in Visual studio, it is working well. Then I created an installation setup. But after installing the service is not firing to popup the dialog window. What will be the reason and how can I fix it?

like image 257
user2147570 Avatar asked Oct 05 '22 06:10

user2147570


2 Answers

Services run in session 0 which is isolated from the interactive desktop. You cannot show UI from a service. You need to run a separate desktop process to show the UI and then use IPC to communicate between the service and the desktop process.

If your dialog is simple enough you could possibly use WTSSendMessage.

If you want to run code at regular intervals then you may be better off with a scheduled task rather than a service.

like image 140
David Heffernan Avatar answered Oct 21 '22 16:10

David Heffernan


How is your service installed? What windows Version are you on?

If vista/7 does Interactive services Detection show up?

Bottom line is windows services where never designed for user interaction.

There is a way however, but I would recommend using a different way to interact with the user

Setting a windows service to interact with the desktop could pose a security issue.

I posted this link Hope it helps

http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/1c3d4b96-c58b-465a-a964-89926bd455f1/

like image 23
Driftware Avatar answered Oct 21 '22 18:10

Driftware