如何在服务上运行Windows GUI应用程序?

时间:2021-04-07 20:45:24

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.

我有一个应该已作为服务实现的现有GUI应用程序。基本上,我需要能够远程登录和退出Windows 2003服务器,并仍然保持此程序运行。

Is this even possible?

这有可能吗?

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

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

11 个解决方案

#1


16  

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.

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

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.

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

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.

如果UI非常简单,您可以使用输入和日志文件的配置文件或输出的Windows事件日志。

#2


6  

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

有没有人使用过第三方产品: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.

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

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

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

#3


4  

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)

您可以将其包装到srvany中,但您可能需要为其分配一个实际的用户帐户(而不是LocalService或其他类似帐户)

#4


2  

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.

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

#5


0  

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.

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

#6


0  

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.

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

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.

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

#7


0  

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.

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

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.

因为,大概是问这个的原因是能够远程监控应用程序,所以这样做的方法是拥有两个应用程序。服务端(基本上是作为控制台应用程序编写)和客户端/监控GUI端。该服务将使用一些远程连接(当我这样做时,我使用命名管道)与客户端/监视应用程序进行通信。要么应该能够在没有其他的情况下运行,当然服务应该能够在客户端运行。

#8


0  

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??

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

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.

我首先想到的是在服务器级虚拟主机(如Virtual Server,HyperV,VMWare)中创建虚拟计算机。这些虚拟机将作为服务运行(或Hyper V所做的任何事情)。无论登录还是退出,虚拟机都将始终运行。

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).

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

#9


0  

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).

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

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).

Active + Software的另一个工具可以是ServiceMill Exe Builder,它允许您从命令行创建服务,如果您使用的是Continuous Integration Server,或者您计划将组件作为服务分发而不必考虑服务集成(加上免版税)。

#10


0  

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

我对winsw有很好的经验。我能够很容易地将我的批处理文件转换为使用它的服务。

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

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

#11


0  

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

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

#1


16  

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.

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

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.

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

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.

如果UI非常简单,您可以使用输入和日志文件的配置文件或输出的Windows事件日志。

#2


6  

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

有没有人使用过第三方产品: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.

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

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

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

#3


4  

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)

您可以将其包装到srvany中,但您可能需要为其分配一个实际的用户帐户(而不是LocalService或其他类似帐户)

#4


2  

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.

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

#5


0  

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.

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

#6


0  

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.

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

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.

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

#7


0  

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.

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

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.

因为,大概是问这个的原因是能够远程监控应用程序,所以这样做的方法是拥有两个应用程序。服务端(基本上是作为控制台应用程序编写)和客户端/监控GUI端。该服务将使用一些远程连接(当我这样做时,我使用命名管道)与客户端/监视应用程序进行通信。要么应该能够在没有其他的情况下运行,当然服务应该能够在客户端运行。

#8


0  

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??

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

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.

我首先想到的是在服务器级虚拟主机(如Virtual Server,HyperV,VMWare)中创建虚拟计算机。这些虚拟机将作为服务运行(或Hyper V所做的任何事情)。无论登录还是退出,虚拟机都将始终运行。

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).

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

#9


0  

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).

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

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).

Active + Software的另一个工具可以是ServiceMill Exe Builder,它允许您从命令行创建服务,如果您使用的是Continuous Integration Server,或者您计划将组件作为服务分发而不必考虑服务集成(加上免版税)。

#10


0  

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

我对winsw有很好的经验。我能够很容易地将我的批处理文件转换为使用它的服务。

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

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

#11


0  

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

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