如何从系统服务创建窗口进度? [英] How to create a window progress from a system service?

查看:43
本文介绍了如何从系统服务创建窗口进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有系统权限的服务。现在我想从这个服务创建一个窗口进度。我怎么能这样做?

请用代码回答我!谢谢!

解决方案

从技术上讲,你没有。 Windows服务没有像常规桌面应用程序那样的桌面。



您可以为服务监视器可以连接的Web服务创建API。然后,当用户登录时,您将运行服务监视器,此监视器可以从Windows服务接收有关启动,进度和完成时间的事件。



如何你可以使用命名管道,MSMQ,远程处理等等。很难说你的具体应用是什么。


感谢您确认我的猜测:您想创建一些UI来显示服务操作的进度。正如Ron在他的解决方案1中正确指出的那样,你不能在服务应用程序中使用UI,因为它是非交互式的,但是有很好的理由:当用户注销时,你的服务应用程序仍然有效,但是没有桌面。



这是一个典型的解决方案:您使用UI开发一个单独的应用程序。通常,您需要在某些用户登录时启动它。最简单的方法是在所有用户的Startup目录中放置一个链接文件。规定此应用程序路径的另一种方法是在运行键下使用注册表。请参阅:

http:// msdn .microsoft.com / zh-CN / library / aa376977%28v = vs.85%29.aspx [ ^ ]。



你可以这样做您的服务安装(卸载时不应忘记卸载)。



现在,当UI应用程序启动时,它应该与您的服务应用程序连接并开始交换数据和事件。由于两个应用程序都在同一台计算机上,因此使用命名管道就足够了:

http://en.wikipedia.org/wiki/Named_pipes [ ^ ],

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365799%28v=vs.85%29.aspx [ ^ ]。



如果还可以是MSMQ或其他消息设施,还有更多。



-SA

I have a service with system authority. Now I want to create a window progress from this service.How can I do it?
Please answer me with code! Thank you!

解决方案

Technically you don't. Windows services don't have a desktop like regular desktop applications.

You can create an API for your web service that a service monitor can connect to. You would then run the service monitor when a user logs in, this monitor can receive events from the windows service about something starting, progress, and when its finished.

How you go about it is up for grabs, either you can use named pipes, MSMQ, remoting, etc. What fits into your specific application is difficult to say.


Thank you for confirming my guess: you want to create some UI to show progress in the service operation. As Ron correctly pointed out in his Solution 1, you cannot have UI in your service application, as it is non-interactive, but quite a good reason: when a user logs off, your service application still works, but there is no a desktop.

Here is a typical solution: you develop a separate application with UI. Typically, you would need to start it up when some user logs on. The a simplest way to do that is to put a link file in the "Startup" directory for all users. Another approach it to prescribe a path to this application is Registry under the key "Run". Please see:
http://msdn.microsoft.com/en-us/library/aa376977%28v=vs.85%29.aspx[^].

You can do this in your service installation (and should not forget to uninstall when uninstalling it).

Now, when the UI application starts, it should connect with your service application and start exchanging data and events. As both applications are on the same computer, using named pipes would be enough:
http://en.wikipedia.org/wiki/Named_pipes[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365799%28v=vs.85%29.aspx[^].

If can also be MSMQ or other messaging facility, and a lot more.

—SA


这篇关于如何从系统服务创建窗口进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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