views:

186

answers:

3

Is it possible to start a program so that it is available to a user with a windows service? I have been working with the Process.Start() in C#. I can get the service to kickoff some sort of process that appears in the Task Manager list under processes. However, the program nevers appears on the screen. By default, it runs under the user name "SYSTEM". I have adjusted the "Log On" option in the service manager to match the person logged into the computer, but this does not cause a window to appear either.

I feel like I am either missing a simple setting, or need to take a different direction for this. Below is the code I have been working with to start up Firefox as a test app.

    private void startRunDap()
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = "Firefox";
        startInfo.WindowStyle = ProcessWindowStyle.Normal;
        startInfo.UseShellExecute = true;
        Process.Start(startInfo);

        //Process.Start("Firefox");

    }
+4  A: 

Put a tick at "Allow service to interact with user" at properties of service in Services

Andrey
Even though it works it is discouraged to do so.
Giorgi
Andrey, that worked like a charm.Giorgi, why is this discouraged?
Swoop
THis does not work with Windows Vista and later, as I understand it.
jwismar
Not only is discouraged, it will stop working as soon as you move out of XP safe heaven. Vista and Windows 7 bot actively forbid this, see http://msdn.microsoft.com/en-us/library/ms683502%28VS.85%29.aspx
Remus Rusanu
Kinda interesting how many devs never even once looked at Vista/Win7. Sounds like XP will be around for a lot longer...
Hans Passant
I doubt my company will be moving from XP any time soon. We still have apps that require IE6, which is still the company standard browser. :( I have Windows 7 at home and love it.
Swoop
+5  A: 

On Vista and Win7 Services run in their own session with a private desktop. You'll get Firefox started but it will never be visible. The account name is actually how this came about, LocalSystem is a highly privileged account, a giant security hole.

You will need an "agent" in the user session to get the process started. An otherwise invisible program that you start with the Run key or the Startup folder that talks to the service through, say, a named pipe or socket. It can start the program.

Hans Passant
+3  A: 

Here's a link to a blog post that describes how to do this in Windows Vista and later. You should note, though, that the first sentences in the article are:

The first thing you should do about it is that; don't do it. There are many limitations and bad implications and restrictions involved.

In case, you are in a state that you cannot avoid launching an interactive process from Windows Service then you might want to read this article.

Windows SDK blog

jwismar