How to launch a Winforms app from a windows-service

回眸只為那壹抹淺笑 提交于 2019-12-11 14:50:08

问题


Hello i am trying to launch an interactive process - a winforms app - from a windows service on the current session. I do not know how to do that.I am using TopShelf and i tried launching the process using the WhenSessionChanged hook provided by TopShelf. I can get the sessionId

 var exitCode = HostFactory.Run(x => {
                    x.Service<MyService>(s => {
                        s.ConstructUsing((h) => new MyService());
                        s.WhenStarted(t => t.Run());
                        s.WhenStopped(t => t.Stop());
                        s.WhenSessionChanged((anubis, args) => {
                              string winformsPath="D://WinFormsApp/Wf.exe"
                              int sessionId = args.SessionId;
                              Process process = new Process();
                              process.StartInfo = new ProcessStartInfo(winformsPath);
                              process.Start();
                         });
                    });
                    x.RunAsLocalSystem();
                    x.SetServiceName(Constants.ISO.NAME);
                    x.SetDisplayName(Constants.ISO.DISPLAY);
                    x.SetDescription(Constants.ISO.DESCRIPTION);
                });

I do not know what to do with the sessionId.
P.S
I did not post the definition of MyService because it is not important in our case.I just want to launch the winforms on the current session.

来源:https://stackoverflow.com/questions/56837380/how-to-launch-a-winforms-app-from-a-windows-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!