ispiro
ispiro

Reputation: 27713

Change the Description of my Windows Service

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.

Upvotes: 7

Views: 18729

Answers (3)

Maineac
Maineac

Reputation: 199

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.

Upvotes: 19

STLDev
STLDev

Reputation: 6174

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

Upvotes: 3

STLDev
STLDev

Reputation: 6174

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.

Upvotes: 1

Related Questions