如何更改 Windows 服务的名称? [英] How do I change the name of my Windows service?

查看:104
本文介绍了如何更改 Windows 服务的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

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

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.

推荐答案

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

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.

您可以在此处查看详细说明:
http://utkarshpuranik.wordpress.com/2010/06/07/creating-installing-debugging-windows-services/

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

这篇关于如何更改 Windows 服务的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆