如何通过窗口服务运行窗口应用程序? [英] How to run Window Application through Window Service?

查看:104
本文介绍了如何通过窗口服务运行窗口应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经创建了一个窗口服务,并且在启动时"事件上我想运行一个窗口应用程序.通过使用以下代码,我可以启动应用程序,但看不到Window窗体.我可以看到任务管理器中正在运行的进程.请帮助.
谢谢.

Hi,
I have created a window service and on "On Start" event i want to run a Window application. By using the below code i am able to initiate the application, but not able to see the Window forms. I can see the process running in Task Manager. Plz Help.
Thanks.

ProcessStartInfo pInfo = new ProcessStartInfo(Path);
pInfo.WindowStyle = ProcessWindowStyle.Maximized;
Process.Start(pInfo);

推荐答案

如果这样做,您将遇到问题. Windows服务旨在运行不需要GUI(图形用户界面)的进程.因此,服务甚至不支持GUI.为了通过GUI运行 软件,您需要具有登录用户.我建议以其他方式启动Windows Forms应用程序.

如果确实要尝试从服务启动进程,请尝试System.Diagnostics命名空间中的Process对象.

祝你好运,
爱德华
You are going to get problems if you do that. A windows service is designed to run processes that don''t require a GUI (Graphical User Interface). For that reason, a service doesn''t even support a GUI. In order to run software with a GUI you''re required to have a logged on user. I recommend starting the Windows Forms application in a different way.

If you do want to try to start a process from a service, try the Process object in the System.Diagnostics namespace.

Good luck,
Eduard


这是不可能的. Windows Service程序在会话ID 0"下运行,其中第一个登录的用户在会话ID 1"中运行. Windows Service运行所在的会话ID 0"下没有用户登录.对于Windows Vista及更高版本,这是正确的.对于Windows XP,Windows Service与第一个登录的ind用户在同一会话ID"下运行.

更好的方法是使用启动文件夹"或"HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run"下的注册表


请参阅链接会话0隔离 [
It is not possible. Windows Service program runs under "Session Id 0", where the first logged in user runs in "Session Id 1". There is no user logged in under "Session Id 0", where your Windows Service runs. This is true for Windows Vista and above. For Windows XP, Windows Service runs under the same "Session Id" as the first logged ind user.

Better way is to use "Startup folder" or registry under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"


See link Session 0 Isolation[^]


"我必须启动客户端服务器应用程序启动时会自动启动应用程序.为了检测服务器应用程序是否正在运行,我正在使用Window Service.但是通过Window service我无法启动客户端应用程序.如果服务器应用程序未运行,则无法启动客户端应用程序甚至是用户.您能建议我我必须使用什么来启动客户端应用程序吗?谢谢."

您可能应该重新考虑您的体系结构,这对我来说听起来不是一个好主意. Windows服务不应基于某些远程服务器应用程序状态尝试启动GUI

我认为应该由用户决定何时要运行某个软件.当他们启动您的应用程序时,如果服务器应用程序一切正常并且已为客户端准备就绪,它将对您的服务器应用程序执行某种检查,并返回正在运行\有效"状态.

如果没有,您应该看到一些标准消息远程服务器不接受连接,请稍后再试".

这真的很容易做到,这取决于您与服务器的通信方式.
"I have to initiate a client application automatically as the server application start. For detecting the server application running or not, i was using the Window Service. But through Window service i am not able to start client application. If server application is not running, client application can not be start even by the user. Can you suggest me what i have to use to initiate client application? Thanks."

You should probably rethink your architecture, this doesn''t sound like a good idea to me. A windows service shouldn''t be trying to start GUIs based on some remote server application status

I think it''s down to the user to decide when they want to run a piece of software. When they start your application, it should perform some sort of check against your server application that returns a ''running \ valid'' status if the server app is all OK and ready for clients.

If not, you should see some standard message ''The remote server is not accepting connections, please try again later''.

This is really easy to do, it just depends how your communicating with your server.


这篇关于如何通过窗口服务运行窗口应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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