是否可以安装同一个delphi服务应用程序的多个实例?

编程入门 行业动态 更新时间:2024-10-26 13:29:36
本文介绍了是否可以安装同一个delphi服务应用程序的多个实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个服务应用程序内置在Delphi,工程很好。它完全是我想要的,一切都很开心。一直到我想要在一台机器上运行该服务的两个(或更多)实例之前,这一切都很好。由于服务名称被硬编码到程序中(通过服务的Name属性),我只能在任何给定的计算机上安装一次服务。如果我尝试在运行时修改Name属性,则除非将Name属性设置为在设计时设置的相同内容,否则该服务不会响应。

我已经做了一个解决方法,我有所有代码不直接与服务控制管理器封装到单独的单元中进行交互。然后我为每个实例编写一个单独的Delphi项目,我想要的服务只有足够的代码启动自己并开始运行主要代码。

这个方法是,在我看来,丑陋肯定是低效的。对于两个实例,它可以正常工作,但是我们需要第三个和第四个...

有什么办法可以修改我的代码,以便我有一个Delphi项目可以通过一些简单的运行时输入(例如命令行标志)安装和运行自己作为多个服务实例?

或者更广泛的问题是:是否有一个正确的方法来完成目标?

解决方案

你还没有清楚你在TService中尝试改变的内容

您是否添加了BeforeInstall处理程序?

某些东西:

procedure TServiceMain.ServiceLoadInfo(Sender:TObject); //新方法,而不是覆盖 begin 名称:= ParamStr 2); DisplayName:= ParamStr(3); 结束 程序TServiceMain.ServiceBeforeInstall(Sender:TService); begin ServiceLoadInfo(Self); 结束 procedure TServiceMain.ServiceCreate(Sender:TObject); begin ServiceLoadInfo(Self); 结束

如果你经常这样做,子类TService在构造函数中执行thie。

您也应该在BeforeUninstall中执行相同的操作 - 同样的方法将两个事件相结合。

C:\> servicename / install MyService我的服务说明

I have a service application built in Delphi that works great. It does exactly what I want it to do and all is happy. All is fine until I want to run two (or more) instances of that service on a single machine. Since the service name is hard coded into the program (via the Name property of the service), I can only install the service once on any given computer. If I try to modify the Name property at run-time, the service does not respond unless the Name property is set to the same thing that was set during design time.

I have done a workaround for this where I have all of the code that is not interacting directly with the service control manager encapsulated out into separate unit(s). Then I write a separate Delphi project for each instance that I want of the service that has just enough code to launch itself and start running the main code.

This method is, in my opinion, ugly and is certainly inefficient. It works okay for two instances, but then we need a third and a fourth and ...

Is there any way that I can modify my code so that I have just one Delphi project that can install and run itself as multiple service instances with some simple run-time input (e.g. command line flag)?

Or perhaps a broader question: Is there a "right way" to accomplish goal?

解决方案

You haven't made it clear what you have tried to change in the TService subclass.

Have you added a "BeforeInstall" handler?

Something like:

procedure TServiceMain.ServiceLoadInfo(Sender : TObject);// new method, not an override begin Name := ParamStr(2); DisplayName := ParamStr(3); end; procedure TServiceMain.ServiceBeforeInstall(Sender: TService); begin ServiceLoadInfo(Self); end; procedure TServiceMain.ServiceCreate(Sender: TObject); begin ServiceLoadInfo(Self); end;

If you do this regularly, subclass TService to do thie in the Constructor instead.

You should do the same in the BeforeUninstall as well - point both events at the same method.

C:\>servicename /install MyService "My Service Description"

更多推荐

是否可以安装同一个delphi服务应用程序的多个实例?

本文发布于:2023-11-16 02:40:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1600260.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   应用程序   实例   delphi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!