41

I have a Windows Service and want to change the name of it (as it appears in the Services application). But I'm unsure of the correct way to do so. It appears to be the ServiceName property and searching through my solution I found this:

namespace SI.AService.AService
{
    partial class AService
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            // 
            // AService
            // 
            this.ServiceName = "Company.AService.AService";

        }

        #endregion
    }
}

So this seems to be autogenerated code. What's the proper way of changing it? It says "do not modify the contents of this method with the code editor." So where do I modify it then?

Update: I was updating my Windows Service through the build process in Visual Studio, which apparently has no effect on name changes set up in the service installer. I think it runs an uninstall and install command with the InstallUtil. Instead I had to go to the output directory of the build process where 2 files are located. An msi-file and a setup.exe file. The msi installs the service, BUT there is no name changes. However if I run the setup.exe, it does the same but name changes to the service are included. So I guess the projectinstaller/serviceinstaller are included in the setup.exe and not the other.

Lastly, thank you all for your help.

Kasper Hansen
  • 6,307
  • 21
  • 70
  • 106

7 Answers7

38

You might have added an installer by right clicking the design view of your Windows service class. If you have done this then you will find a ProjectInstaller class within your WindowsService project.

By selecting this ProjectInstaller class you will find two installers on its design view -> 1.ServiceInstaller1 2.ServiceProcessInstaller1

Right click the ServiceInstaller1 and select properties. In the properties window change the ServiceName to the name you want to give to your service.

Hope this works...

Harun
  • 5,109
  • 4
  • 38
  • 60
  • 11
    +1 for "right click the design view of your Windows service class"... That's not immediately obvious, and I've been using VS for 10 years X-D – Chris Ray Oct 31 '13 at 16:02
  • 1
    ALso see here for the MSDN walkthrough. This is not easy at all. In your actual project (not the setup/install project, but your service project), you should have a ProjectInstaller.cs. Right click - design. Then click on ServiceInstaller1 which finally shows the serviceName property in the properties window. HERE you set the service name. Whew. http://msdn.microsoft.com/en-us/library/zt39148a%28v=vs.110%29.aspx – Rob Dec 09 '14 at 17:42
  • Best answer. Step by step explanation and spot on. Thanks! – Source Matters Aug 19 '18 at 07:01
27

You have to add an installer class to your Windows service project. Then in its designer you add ServiceInstaller and ServiceProcessInstaller, in objects of these two classes you can specify Service name, display name for service, user etc.

You can see detailed explanation here:
http://utkarshpuranik.wordpress.com/2010/06/07/creating-installing-debugging-windows-services/

Utkarsh
  • 632
  • 1
  • 9
  • 19
12

in VS2012 and 2015, if you want to change it in VS designer, double click on your service class file e.g. MyCustomService.cs and then in design view right click and choose Properties.

enter image description here

that gives you the option to visually change the service name.

enter image description here

Ryan
  • 615
  • 8
  • 19
7

In Visual Studio 2010, you could double click the entry for the service file in the Solution Explorer (named "AService" in your case). In the properties window, just change the entry under "ServiceName".

Jimmy W
  • 539
  • 3
  • 11
4

None of the above work for me, so sharing what works actually Go to your file "ProjectInstaller.Designer.cs" and upadate the line:

this.serviceInstaller1.ServiceName = "Updated Name";

It should be under method: InitializeComponent()

Hope it helps someone!!!

Suresh Kamrushi
  • 15,627
  • 13
  • 75
  • 90
3

It depends on the way you install it

  • If you use SC.EXE then just change the display name parameter
  • If you use ServiceInstaller Class then change its DisplayName
Wojtek Turowicz
  • 4,086
  • 3
  • 27
  • 38
1

A picture sometime worth thousand words so i thought i gave you this image with annotation:

It should be simple.

enter image description here

Dung
  • 19,199
  • 9
  • 59
  • 54