如何更改Windows服务的名称?

Kas*_*sen 34 c# windows-services

我有一个Windows服务,并希望更改它的名称(因为它显示在服务应用程序中).但我不确定这样做的正确方法.它似乎是ServiceName属性,并通过我的解决方案搜索我发现:

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
    }
}
Run Code Online (Sandbox Code Playgroud)

所以这似乎是自动生成的代码.改变它的正确方法是什么?它说"不要使用代码编辑器修改此方法的内容." 那么我在哪里修改呢?

更新:我通过Visual Studio中的构建过程更新了我的Windows服务,这显然对服务安装程序中设置的名称更改没有影响.我认为它使用InstallUtil运行卸载和安装命令.相反,我必须转到2个文件所在的构建过程的输出目录.一个msi文件和一个setup.exe文件.msi安装服务,但没有名称更改.但是,如果我运行setup.exe,它会执行相同的操作,但包含对服务的名称更改.所以我猜projectinstaller/serviceinstaller包含在setup.exe中而不包含在另一个中.

最后,谢谢大家的帮助.

Har*_*run 33

你可能会通过右键单击添加的安装设计视图您的Windows服务类.如果您已完成此操作,那么您将在WindowsService项目中找到ProjectInstaller类.

通过选择此ProjectInstaller类,您将在其设计视图中找到两个安装程序 - > 1.ServiceInstaller1 2.ServiceProcessInstaller1

右键单击ServiceInstaller1并选择属性.在属性窗口中,将ServiceName更改为要服务指定的名称.

希望这有效......

  • +1"右键单击Windows服务类的设计视图"......这不是很明显,我已经使用VS 10年了XD (10认同)

Utk*_*rsh 25

您必须向Windows服务项目添加安装程序类.然后在其设计器中添加ServiceInstaller和ServiceProcessInstaller,在这两个类的对象中,您可以指定服务名称,服务的显示名称,用户等.

你可以在这里看到详细的解释:http:
//utkarshpuranik.wordpress.com/2010/06/07/creating-installing-debugging-windows-services/


Jim*_*y W 6

在Visual Studio 2010中,您可以在解决方案资源管理器中双击服务文件的条目(在您的案例中名为"AService").在属性窗口中,只需更改"ServiceName"下的条目即可.


Rya*_*yan 5

在VS2012和2015年,如果你想改变它在VS设计师,双击服务类文件,例如MyCustomService.cs,然后在设计视图中单击鼠标右键,然后选择属性.

在此输入图像描述

这使您可以选择直观地更改服务名称.

在此输入图像描述