我有一个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
}
}
所以这似乎是自动生成的代码。改变它的正确方法是什么?它说“不要使用代码编辑器修改此方法的内容。”那么我在哪里修改呢?
更新:我正在通过Visual Studio中的构建过程更新我的Windows服务,这显然对服务安装程序中设置的名称更改没有影响。我认为它使用InstallUtil运行卸载和安装命令。相反,我必须转到2个文件所在的构建过程的输出目录。一个msi文件和一个setup.exe文件。 msi安装服务,但没有名称更改。但是,如果我运行setup.exe,它会执行相同的操作,但包含对服务的名称更改。所以我猜projectinstaller / serviceinstaller包含在setup.exe中而不包含在另一个中。
最后,谢谢大家的帮助。
答案 0 :(得分:33)
您可能通过右键单击 Windows服务类的设计视图添加了安装程序。如果您已完成此操作,那么您将在WindowsService项目中找到 ProjectInstaller类。
通过选择此 ProjectInstaller 类,您将在其设计视图中找到两个安装程序 - &gt; 的 1.ServiceInstaller1 2.ServiceProcessInstaller1 强>
右键单击ServiceInstaller1并选择属性。在属性窗口中,将ServiceName更改为您想要的名称,以便为您的服务提供。
希望这有效......
答案 1 :(得分:25)
您必须向Windows服务项目添加安装程序类。然后在其设计器中添加ServiceInstaller和ServiceProcessInstaller,在这两个类的对象中,您可以指定服务名称,服务的显示名称,用户等。
您可以在此处查看详细说明:
http://utkarshpuranik.wordpress.com/2010/06/07/creating-installing-debugging-windows-services/
答案 2 :(得分:6)
在Visual Studio 2010中,您可以在解决方案资源管理器中双击服务文件的条目(在您的情况下命名为&#34; AService&#34;)。在属性窗口中,只需更改&#34; ServiceName&#34;。
下的条目答案 3 :(得分:5)
在VS2012和2015中,如果要在VS设计器中更改它,请双击您的服务类文件,例如MyCustomService.cs然后在设计视图中右键单击并选择Properties。
可让您选择直观地更改服务名称。
答案 4 :(得分:3)
这取决于你安装它的方式
答案 5 :(得分:2)
以上都不适合我,因此请分享实际可行的方法 转到文件“ ProjectInstaller.Designer.cs”并更新该行:
this.serviceInstaller1.ServiceName = "Updated Name";
它应该在方法下: InitializeComponent()
希望它对某人有帮助!
答案 6 :(得分:-1)