2

我想通过服务运行用c#winform制作的应用程序。我已经完成了代码,但是即使服务成功启动,应用程序也没有启动并且没有抛出异常。

protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("starting Kb");
            try
            {
                Process myProcess = new Process();
                myProcess.StartInfo.FileName = @"C:\Program Files (x86)\Invisual E. Inc\KeyboardSetup\keyboard.exe";//Exe Path 
                myProcess.StartInfo.CreateNoWindow = false;
                myProcess.EnableRaisingEvents = true;

                myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;


                myProcess.Start();
                ProcessWindowStyle ws = myProcess.StartInfo.WindowStyle;
                if (ws == ProcessWindowStyle.Hidden)
                    myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;

                eventLog1.WriteEntry("started");

            }
            catch (Exception c)
            {
                eventLog1.WriteEntry(c.Message);
            }
        }

日志文件没有显示任何异常。

目的是在窗口的欢迎屏幕上启动应用程序,以便用户可以使用定制的键盘。

4

2 回答 2

2

What operating system? From Vista and beyond you cannot create GUI from services (it's a security flaw and ugly...) There is a user 0 session that shows gui started by services from vista onwards.

Why not create a registry entry and/or startup entry for your app to start when the user who installed your app logs in? Or follow the info here about implementing an interactive service.

于 2011-06-25T09:00:59.623 回答
0

A service normally runs under a user other than the logged in user therefore the service doesn't have a desktop available to display any windows form, hence the reason t isn't being displayed.

I think you will need to find another way as although a winforms app can start a service I dont believe it can be done the other way around.

Regards

AJ

于 2011-06-25T09:00:47.927 回答