Windows services 如何从指定名称和说明的命令行安装windows服务?
我用Delphi为客户机-服务器应用程序创建了一个Windows服务 要安装它,我使用Windows services 如何从指定名称和说明的命令行安装windows服务?,windows-services,shellexecute,Windows Services,Shellexecute,我用Delphi为客户机-服务器应用程序创建了一个Windows服务 要安装它,我使用 c:\Test\MyService.exe /install (or /uninstall) 这将安装服务,并在Windows服务中列出“MyService”名称和空描述 如何定义不同的名称并插入说明(在运行services.msc时可以看到) 注: 我之所以需要它,是因为在同一台机器上,我需要多次安装相同的服务(每个数据库1次) 目前,我唯一的解决办法是重命名服务exe,但我更希望找到正确的命令行方法(因
c:\Test\MyService.exe /install (or /uninstall)
这将安装服务,并在Windows服务中列出“MyService”名称和空描述
如何定义不同的名称并插入说明(在运行services.msc
时可以看到)
注:
我之所以需要它,是因为在同一台机器上,我需要多次安装相同的服务(每个数据库1次)
目前,我唯一的解决办法是重命名服务exe,但我更希望找到正确的命令行方法(因为我是从ShellExecute
执行此操作的)
更新:
不知何故,我会寻找这样的东西(当然,这只是为了解释原因!-InstallService.exe
是我刚刚发明的一个名称):
但也可以使用更紧凑的版本,如:
c:\Test\MyService.exe /install /name='MyService1'
/description='This is my service for database 1'
Windows已经附带了您需要的实用程序,即
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=
另一个明显的选择是在服务中构建命令行解析。这很容易做到。只需在安装前和/或安装后事件分配服务的
处理程序,并在那里处理开关即可。非常感谢。我从命令行中尝试了所有的方法,结果一切正常。它还可以与相同的exe同时运行(当然是不同的[service name]。此外,sc delete[service name]
关闭循环示例:---一些容易遗漏的内容(即使在sc的描述中)就是在binPath=之后需要一个空格,所以不能执行binPath=mypath,而必须执行binPath=mypath+1。我不明白为什么这个问题值得一个downvoteNote,即DelphiTService
在使用与name
属性不同的名称创建服务时无法启动该服务。有关问题的描述,请参阅orkaround.@Jerry-这是个不错的问题,但似乎离题了。也许这可以解释投票结果。超级用户更适合回答“如何使用此命令”的问题。
>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=
>sc description /?
DESCRIPTION:
Sets the description string for a service.
USAGE:
sc description [service name] [description]