How to install a windows service from command line specifying name and description?

感情迁移 提交于 2019-11-30 11:57:53

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!