如何将 Windows GUI 应用程序作为服务运行?

发布于 2024-07-06 03:07:46 字数 139 浏览 6 评论 0原文

我有一个现有的 GUI 应用程序,应该将其实现为服务。 基本上,我需要能够远程登录和注销 Windows 2003 服务器,并且仍然保持该程序运行。

这可能吗?

编辑:这里进一步细化...我没有来源,这不是我的应用程序。

I have an existing GUI application that should have been implemented as a service. Basically, I need to be able to remotely log onto and off of the Windows 2003 server and still keep this program running.

Is this even possible?

EDIT: Further refinement here... I do not have the source, it's not my application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

烏雲後面有陽光 2024-07-13 03:07:48

我在 winsw 方面有很好的经验。 我可以使用它轻松地将批处理文件转换为服务。

我也将它用于 nginx,根据 这个答案

I've had good experience with winsw. I was able to convert quite easily my batch files to services using it.

I've used it for nginx as well, per this answer.

忆伤 2024-07-13 03:07:48

您实际上需要它作为服务运行,还是只需要它在未连接时保持运行? 如果是后者,您可以断开连接而不是注销,应用程序将继续运行。 该选项应位于选择“关闭”后的下拉列表中,或者您可以调用 tsdiscon.exe。

Do you actually need it to run as a service or do you just need it to stay running when you aren't connected? If the latter, you can disconnect instead of logging off and the application will continue running. The option should be in the drop down list after choosing Shut Down or you can call tsdiscon.exe.

半仙 2024-07-13 03:07:48

您可以使用 ServiceMill 来实现此操作。
基本上,您在服务器上安装 ServiceMill Server。
然后单击可执行文件上的右键并“安装为 ServiceMill 服务”。
接下来,您配置一些内容(用户/密码,如果您想与桌面交互或者您喜欢隐藏用户界面...并将启动模式设置为自动)。

Active+ Software 的另一个工具可以是一个解决方案,ServiceMill Exe Builder,它允许您创建服务如果您正在使用持续集成服务器,或者您计划将组件作为服务分发而无需考虑服务集成(而且它是免版税的),那么这非常有用。

You can use ServiceMill to achieve this operation.
Basically you install ServiceMill Server on your server.
Then click on right button over your executable file and "Install as a ServiceMill Service".
Next you configure some things (user/password, if you want to interact with desktop or if you prefer to hide the ui... and set the start mode to automatic).

Another tool from Active+ Software can be a solution, ServiceMill Exe Builder which allows you to create services from Command Line and this is great if you are using a Continuous Integration Server or if you plan to distribute your component as a service without having to think about service integration (plus it is royalty free).

属性 2024-07-13 03:07:48

您可以将其包装到 srvany 中,尽管您可能需要为其分配一个实际的用户帐户(如反对 LocalService 或类似的服务)

You can wrap it up into srvany, though you may need to assign it an actual user account (as opposed to LocalService or some such)

夏至、离别 2024-07-13 03:07:48

有没有人使用过第三方产品,例如:Always Up

似乎做了我需要的事情。 这是我需要的在登录/注销周期中保持运行的能力。 并且能够忽略它是一个 GUI 应用程序并无论如何运行它。

他们必须手动链接到 exe 并调用 WinMain 或其他东西。

Has anyone used a third party product like: Always Up?

Seems to do what I need. It's the capability to keep running through login / logout cycles I need. And the capability to ignore that it's a GUI app and run it anyway.

They must be linking into the exe manually and calling WinMain or something.

客…行舟 2024-07-13 03:07:48

服务不应该有 GUI,因为它应该在不需要用户任何干预的情况下运行,并且存在与查找正确的用户桌面并与其通信相关的各种问题。

因为,提出这个问题的原因可能是为了能够远程监视应用程序,所以实现此目的的方法是拥有两个应用程序。 服务端(基本上编写为控制台应用程序)和客户端/监控 GUI 端。 该服务将使用一些远程连接(当我这样做时,我使用命名管道)与客户端/监控应用程序进行通信。 任何一个都应该能够在没有另一个的情况下运行,当然服务也应该能够在没有客户端的情况下运行。

A service shouldn't have a GUI, since it should run without any needing any intervention from a user, and there are all sorts of problems associated with finding and communicating with the correct users desktop.

Since, presumably the reason for asking this is to be able to remotely monitor the application, the way to do it would be to have two applications. The service side (written basically as a console application) and the client/monitoring GUI side. The service would use some remote connectivity (when I did this I used Named Pipes) to communicate with the client/monitoring application. Either should be able to run without the other, and certainly the service should be able to run with out the client.

东北女汉子 2024-07-13 03:07:48

首先我不得不问为什么你的服务需要用户界面。 很可能不会,但您可能需要一个从该服务获取数据的客户端。 服务通常没有 GUI 的原因是它们可能没有运行的窗口环境。服务可以在用户不登录到计算机的情况下启动和运行。 在这种情况下,将没有桌面供服务 GUI 运行。

话虽如此,您可以按照 Mark 的建议设置服务的属性以作为用户运行。 您还可以在服务的属性中指定“允许服务与桌面交互”。 仅当您知道用户将登录时才执行此操作。

First I would have to ask why your service needs a user interface. Most likely it does not but you probably need a client that gets data from this service. The reason services don't usually have GUI's is they may not have a window environment to run in. Services can start and run without a user logged in to the machine. In this case there would be no desktop for the service GUI to run in.

Having said that you can set properties on the service to run as a user as suggested by Mark. You can also specify in the properties of the service to "Allow service to interact with desktop". Only do this if you know a user will be logged in.

撩起发的微风 2024-07-13 03:07:48

你有源码吗? 在许多情况下,独立应用程序和服务之间的差异很小。

大多数更改与将代码正确挂接到服务管理器有关。 完成后,您就会知道发生的任何问题都是您的编程造成的,而不是任何其他程序造成的。

Do you have the source? In many cases the difference between a stand alone application and a service are minimal.

Most of the changes are related to hooking the code into the service manager properly. Once done, you'll know that any problems that occur are a result of your programming and not any other program.

抚笙 2024-07-13 03:07:48

如果您创建服务会发生什么。 该服务配置为与桌面交互。 将其配置为运行某个用户并自动启动。 来自此其他应用程序上的服务 CreateProcess。 我猜想尝试使用 C# 很快(如果我记得的话,C/C++ 有很多代码,甚至可以成为一项服务)。 那行吗?

但!

我的第一个想法是在服务器级虚拟主机(如虚拟服务器、HyperV、VMWare)中创建虚拟计算机。 这些虚拟机将作为服务运行(或者 Hyper V 所做的任何事情)。 虚拟机将始终运行 - 无论登录和退出。

使该虚拟计算机自动登录到 Windows(TweakUI 可以进行设置),然后使用 Startup 文件夹的快捷方式启动 GUI 应用程序。 您甚至可以使用程序的 GUI 进行远程桌面访问(我敢打赌 Always Up 不能做到这一点)。

What happens if you create a service. That service is configure to interact with the desktop. Configure it to run a some user and to start automatic. From the service CreateProcess on this other application. I'd guess this is quick to try using C# (C/C++ was alot of code to even be a service if I recall). Would that work??

BUT!

My first thought would be to create a virtual computer in a server-class virtual host (like Virtual Server, HyperV, VMWare). Those virtual machines will run as service (or whatever Hyper V does). The virtual machine would always be running - regardless of logging in and out.

Make this virtual computer auto login to windows (TweakUI can set this up) and then just launch the GUI app using a shortcut to the Startup folder. You can even remote desktop into it use the program's GUI (I bet Always Up can't do that).

安静被遗忘 2024-07-13 03:07:48

FireDaemonPro 将大多数 GUI 应用程序转变为服务; 它不是免费的,但可能值得获得。

FireDaemonPro turns most GUI apps into services; it's not free, but it might be worth getting it.

盛夏尉蓝 2024-07-13 03:07:46

Windows 服务不能有 GUI,因此您需要摆脱 GUI 或将应用程序分成两部分 - 一个没有 UI 的服务和一个“控制器”应用程序。 如果您有源代码,则将非 GUI 代码转换为服务很容易 - Visual Studio 有一个“Windows 服务”项目类型,可以为您处理包装,并且有一个简单的演练向您展示如何创建负责安装的部署项目。

如果您选择第二条路线并且需要将一些原始 GUI 代码放入控制器中,则控制器和服务可以通过 WCF、.NET Remoting 或使用您自己定义的协议的普通套接字连接进行通信。 如果您使用远程处理,请确保使用“块状”接口,以尽可能少的方法调用来传输数据 - 每个调用都有相当大的开销。

如果 UI 相当简单,您也许可以不用使用配置文件作为输入和日志文件,或者使用 Windows 事件日志作为输出。

Windows services cannot have GUIs, so you will need to either get rid of the GUI or separate your application into two pieces - a service with no UI, and a "controller" application. If you have the source code, converting the non-GUI code into a service is easy - Visual Studio has a 'Windows Service' project type that takes care of the wrapping for you, and there is a simple walkthrough that shows you how to create a deployment project that will take care of installation.

If you opt for the second route and need to put some of the original GUI code into a controller, the controller and service can communicate via WCF, .NET Remoting or plain socket connections with a protocol you define yourself. If you use Remoting, be sure to use a "chunky" interface that transfers data with as few method invocations as possible - each call has a fair amount of overhead.

If the UI is fairly simple, you may be able to get away with using configuration files for input and log files or the Windows Event Log for output.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文