How can I start a browser from a windows service

醉酒当歌 提交于 2019-12-25 00:39:19

问题


I need to create a windows service that when launced open a specific URL. What I did is to override the onStart() method by adding the following lines :

protected override void OnStart(string[] args)

    {
        eventLog1.WriteEntry("Browser must start " + DateTime.Now);
        string targetURL = "http://www.mysite.com";
        System.Diagnostics.Process.Start(targetURL);
    }

However this thing doesn`t work . :(( Thing is that it does write the log .than means that onStart Anybody has any ideas????


回答1:


The service is usually started (when it's in Automatic startup mode) when there's no user logged in.

In general, services don't interact with user desktop and work in a separate session. If you need something to be performed for each or some of logged in users, you need to write a separate agent application, which will be automatically started on user login, and with which your service will communicate. Then the agent can start the browser or do whatever else you need.




回答2:


Simple answer is, if you're using Vista or later you can't. This is due to session 0 isolation. To quote from the document linked in that page:

For more complex interactions, developers should move their UI code into an agent that runs in the user’s session and handles all UI requirements. The agent communicates with the service through RPC or named pipes.




回答3:


Windows services don't have a GUI. What you can do is create a controller that interacts with your service and have it launch a web browser.

This link doesn't directly answer your question but contains enough links in the answers to put you on the right path: How can I run a Windows GUI application on as a service?



来源:https://stackoverflow.com/questions/4873005/how-can-i-start-a-browser-from-a-windows-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!