开发者

How do you program a windows service in C# to start an application for a user?

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.U开发者_开发百科seShellExecute = true;
        Process.Start(startInfo);

        //Process.Start("Firefox");

    }


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜