5

According to this answer it seems that there is no official way to set a version for a Windows Service. However this can be done by inserting it into its Description or DisplayName.

I would like to be able to change that version number without needing to delete and reinstall the service. But I couldn't find a way to set the Description except for in the installation itself.

So, is there a way, and what is it, to change a Service's Description without reinstalling it?

Preferably using .Net. The Service itself is also .Net if that matters.

ispiro
  • 26,556
  • 38
  • 136
  • 291
  • Service descriptions are kept in the registry under LocalMachine\System\CurrentControlSet\services and then open the key for your service name, one of the keys is `Description` which holds the description text. Change that and restart the computer. – Ron Beyer May 10 '18 at 20:49
  • In my company we are using [TopShelf](http://topshelf-project.com/) for windows services. It's easy to install and uninstall, you just use the console... You can set the service name and description from code (take it form app.config, for instance) – Zohar Peled May 10 '18 at 20:51

3 Answers3

16

This can be accomplished using the SC.exe utility with the command:

sc description <ServiceName> "Any Description you like."

This command could be called from a command window opened as administrator or from a .Net application provided that the service has already been created.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Maineac
  • 169
  • 1
  • 3
  • 1
    I have to correct my own omission. The command is: sc description "Any Description you like." The quotations are required if there are spaces in the description. Don't include the <> in the service name. – Maineac Jun 24 '19 at 20:59
2

Though this is not a pure .NET solution, it can be implemented in .NET, and it is one of the only MS-supported methods of reconfiguring a service. Plus, it doesn't require direct registry manipulation (best avoided if possible).

You can change the description of a Windows service by using the Windows command-line service controller utility, SC.exe.

You can exec the command you need to execute from your .NET code, or call it from a shell or script, such as CMD.exe or PowerShell.

sc.exe config YourServiceName displayName= "Your service description..."

Note:

  • Detailed information on the SC config command can be found here: MS Docs SC Config man page
  • YourServiceName is the actual service name of your application, not it's current DisplayName (unless, of course, they're identical)
  • If your DisplayName is more than one word, it needs to be wrapped in quotes
  • There must be no space between the word "displayName" and the equals sign
  • There must be one or more spaces between equals sign and the beginning of your desired service description
STLDev
  • 5,950
  • 25
  • 36
  • 6
    Question was about Description, though DisplayName was mentioned too. Your answer is about changing displayName, though you worded it as **You can change the description** – Sergey Nudnov Oct 12 '19 at 15:22
  • 4
    @ispiro This answer which you accepted is misleading. You asked about **Change description**. Answer is about **You can change the description**. In fact, this answer is about changing displayName. People who would follow this answer, could break their system by changing Display Name for the service incorrectly, because it could be used in the scripts, manipulating a service. Look below for an [answer from Maineac](https://stackoverflow.com/a/56741847/9921853) – Sergey Nudnov Oct 12 '19 at 15:30
1

If what you need is the version number of the executable for the Windows service, and the executable is a .NET assembly, then retrieve the path to the service executable, and then retrieve the version from that executable/assembly.

STLDev
  • 5,950
  • 25
  • 36
  • This is basically the other answer in the link I provided. While this might be helpful (+1), It's not exactly what I'm looking for. The version might be different for the service (service name, start options, etc.) than for the exe. I now see it's at least partly my fault. Edited the question to be clearer. – ispiro May 10 '18 at 21:01
  • No worries. I didn't get that from your question. – STLDev May 10 '18 at 21:02