views:

88

answers:

5

I want to pop a browser with a given url from within a windows service. Like so:

System.Diagnostics.Process.Start("http://www.venganza.org/");

Works fine when running in a console but not from within the service. No error messages, no exceptions, the Process.Start() command just seem to do nothing. It smells of some security issue, maybe something with the service properties and/or logon options? Annoying stuff this... Anybody? (Oh, and on windows 7/.NET framework 3.5.)

+3  A: 

A service should never pop up anything to the user. Don't do this with a service.

You will problably need elevated rights to do this aswell. You will have to sign in as the user.

Even if you manage to do this, don't. This is not what services is ment for and it is really bad practise. If you really want someting to pop up, have a seperate process instead.

Oskar Kjellin
A: 

It is popping up, but on the Window Station associated with the service.

I would suggest that you tweak your design such that your service doesn't need to interact in this manner. There are ways to get it to appear on an interactive desktop (you'd have to cope with issues such as impersonating the relevant user, targeting the correct desktop if nobody is logged on or if more than one person is logged on, etc.)

Rowland Shaw
And the WindowStation associated with a service is typically not interactive, see http://msdn.microsoft.com/en-us/library/ms687105%28VS.85%29.aspx. And also don't forget that there might be several user sessions on a machine. How to decide which user should see the window?
0xA3
@0xA3 That's why I said about coping with those issues if you really wanted to go down this route.
Rowland Shaw
+3  A: 

I think you ran into a simmilar issue like described in this post

Felix
The best way to handle this is to write a system tray component that can pop up any message you want to present to the user. If you use TCP/IP as the notification mechanism, you also gain the ability to have people monitor from other machines.
Jim Rush
A: 

Just on a side note Windows services aren't built for interactivity. They are used to process behind-the-scenes type stuff. However, have you tried enabling the Interact with Desktop option on the service itself?

James
Oh yes, I've tried the 'interact with desktop' option. Didn't work. I've come to agree that popping gui from a service is a bad idea in the first place. But then a new question arises: What is the 'interact with desktop' option for?
BaBu
I believe it is *technically* for testing as it does allow services to interact with GUI applications. Perhaps a console application is not considered a *GUI* to a service? Try it with a forms application just for clarity.
James