14

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'
Custodio
  • 7,430
  • 12
  • 75
  • 110
LaBracca
  • 13,941
  • 34
  • 129
  • 224
  • 3
    +1 I don't see why this question deserved a downvote – Jerry Dodge Aug 29 '13 at 15:10
  • Note that Delphi `TService` fails to start the service when it is created with a name different to the `Name` property. See [Service does not start](http://stackoverflow.com/q/18599201/859646) for a description of the problem and a workaround. – JRL Sep 03 '13 at 22:11
  • @Jerry - its not a bad question, but it appears to be off-topic. Perhpas that would explain the downvote. Super User is more appropriate for "how do I use this command" questions. – jww Sep 10 '14 at 21:33

1 Answers1

14

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.

David Heffernan
  • 572,264
  • 40
  • 974
  • 1,389
  • THanks a lot. I tried all from command line and it works as expected. It works also with the same exe insatlled meany times (of course eith diffrent [service name]. – LaBracca Aug 29 '13 at 12:29
  • 2
    moreover `sc delete [service name]` closes the loop – LaBracca Aug 29 '13 at 12:43
  • 2
    **Examples:** [Knowledge Base Microsoft](http://support.microsoft.com/kb/251192) -- [Create, Query, Stop and Delete examples](http://www.herongyang.com/Windows/Service-Create-Delete-Services-with-sc-exe.html) -- [Discussion about parameters](http://stackoverflow.com/questions/3663331/creating-a-service-with-sc-exe-how-to-pass-in-context-parameters) – Custodio Sep 05 '14 at 19:45
  • 4
    Something easy to miss (even if its in the description of sc) is that you need a space after binPath=, so you cannot do binPath=mypath, instead you must do binPath= mypath – Robert Aug 21 '15 at 11:14