Reputation: 67
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????
Upvotes: 0
Views: 2158
Reputation: 5256
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.
Upvotes: 2
Reputation: 46050
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.
Upvotes: 3
Reputation: 1132
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?
Upvotes: 1