服务启动进程不会显示GUI C# [英] Service starting a process wont show GUI C#

查看:155
本文介绍了服务启动进程不会显示GUI C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个服务来启动我的程序,但它没有显示的图形用户界面。该进程启动,但没有显示。我试图让允许服务与桌面交互,但仍然不能正常工作。
我的程序是计算机锁定装置从访问计算机阻止未经授权的用户。我运行Windows 7 64位操作系统。

Hey, I am trying to get a service to start my program but it isn't showing the GUI. The process starts but nothing is shown. I have tried enabling 'Allow service to interact with desktop' but that still isn't working. My program is a computer locking device to stop unauthorised users from accessing the computer. I am running windows 7 with a 64 bit OS.

下面是code为我服务:

Here is the code for my service:

        protected override void OnStart(string[] args)
    {
        Process p = new Process();
        p.StartInfo.FileName = "notepad.exe";
        p.Start();

        FileStream fs = new FileStream(@"C:\Users\David\Documents\Visual Studio 2010\Projects\LockPCService\LockPCService\bin\Debug\ServiceLog.dj",
        FileMode.OpenOrCreate, FileAccess.Write);
        StreamWriter m_streamWriter = new StreamWriter(fs);
        m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
        m_streamWriter.WriteLine(" LockPCService: Service Started " + DateTime.Now + "\n" + "\n");
        m_streamWriter.Flush();
        m_streamWriter.Close();
    }

    protected override void OnStop()
    {
        FileStream fs = new FileStream(@"C:\Users\David\Documents\Visual Studio 2010\Projects\LockPCService\LockPCService\bin\Debug\ServiceLog.dj",
        FileMode.OpenOrCreate, FileAccess.Write);
        StreamWriter m_streamWriter = new StreamWriter(fs);
        m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
        m_streamWriter.WriteLine(" LockPCService: Service Stopped " + DateTime.Now + "\n"); m_streamWriter.Flush();
        m_streamWriter.Close();
    }

要尝试并获得服务的工作我使用的notepad.exe。当我看记事本进程正在运行,但没有图形用户界面。另外,ServiceLog是存在的,我每次运行时的工作。

To try and get the service working I am using notepad.exe. When I look at the processes notepad is running but there is no GUI. Also the ServiceLog is there and working each time I run it.

为什么任何想法是不工作?

Any ideas on why this isn't working?

感谢。

推荐答案

本文解释会话0隔离除其他外,从建立在Windows Vista / 7的UI不允许的服务。在服务启动另外一个进程,它开始在会话0,也不会显示任何UI。 (顺便说一下,用户界面​​被创建,它只是会话0永远不会显示)。 在$ C $的CProject这篇文章可以帮助你从一个服务创建一个进程用户的桌面和显示其用户界面。

This article explains Session 0 Isolation which among other things disallows services from creating a UI in Windows Vista/7. In your service starts another process, it starts in Session 0 and also will not show any UI. (By the way, the UI is created, it's just that Session 0 is never displayed). This article on CodeProject can help you create a process from a service on the user's desktop and show its UI.

另外,请考虑您包装在使用 流对象语句使他们妥善处理。

Also, please consider wrapping you stream objects in a using statement so that they are properly disposed.

这篇关于服务启动进程不会显示GUI C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆