如何从指定名称和描述的命令行安装 Windows 服务? [英] How to install a windows service from command line specifying name and description?
问题描述
我使用 Delphi 为客户端服务器应用程序创建了一个 Windows 服务.
要安装它,我使用
c:\Test\MyService.exe/install(或/uninstall)
这会安装服务,并在 Windows 服务中列出MyService"名称和空描述.
如何定义不同的名称并插入描述(运行services.msc
时可见)?
注意:我需要这个,因为在同一台机器上我需要安装更多次相同的服务(每个数据库 1 个).
目前我发现的唯一解决方法是重命名服务 exe,但我更愿意找出正确的命令行方式来执行此操作(因为我是从 ShellExecute
执行此操作的).>
更新:不知何故,我会寻找类似的东西(当然这只是出于解释原因! - InstallService.exe
是我刚刚发明的名称):
InstallService.exe c:\Test\MyService.exe/install/name='MyService1'/description='这是我为数据库 1 提供的服务'
但更紧凑的版本也可以,例如:
c:\Test\MyService.exe/install/name='MyService1'/description='这是我为数据库 1 提供的服务'
Windows 已经附带了您需要的实用程序,即 sc create
.
这将创建服务并允许您指定名称和显示名称.
修改你需要的描述sc description
:
<小时>
另一个明显的选择是将命令行解析构建到您的服务中.这很容易做到.只需为服务的 BeforeInstall
和/或 AfterInstall
事件分配处理程序并处理那里的开关.
I created a Windows service with Delphi for a client server application.
To install it I use
c:\Test\MyService.exe /install (or /uninstall)
This installs the service and in Windows services it lists with "MyService" name and empty description.
How to define a different name and insert a description (to be seen when running services.msc
)?
Note: I need this because on the same machine i need to install more times the same service (1 per database).
Currently the only workaround i foudn is to rename the service exe, but I'd prefer to find out the correct command line way to do it (since I do this from ShellExecute
).
Update:
Somehow i'd look for something like (this is just for explanation reasons of course! - InstallService.exe
is a name i just invented):
InstallService.exe c:\Test\MyService.exe /install /name='MyService1'
/description='This is my service for database 1'
but also a more compact version would be fine like:
c:\Test\MyService.exe /install /name='MyService1'
/description='This is my service for database 1'
Windows already ships with the utility that you need, namely sc create
.
>sc create /? DESCRIPTION: Creates a service entry in the registry and Service Database. USAGE: sc create [service name] [binPath= ] ... OPTIONS: NOTE: The option name includes the equal sign. A space is required between the equal sign and the value. type= (default = own) start= (default = demand) error= (default = normal) binPath= group= tag= depend= obj= (default = LocalSystem) DisplayName= password=
This will create the service and allow you to specify the name and display name.
To modify the description you need sc description
:
>sc description /? DESCRIPTION: Sets the description string for a service. USAGE: sc description [service name] [description]
The other obvious option is to build command line parsing into your service. That's trivially easy to do. Simply assign handlers for the service's BeforeInstall
and/or AfterInstall
events and process the switches there.
这篇关于如何从指定名称和描述的命令行安装 Windows 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!