2009-01-27 45 views

回答

25

创建的ServiceInstaller并设置描述

private System.ServiceProcess.ServiceInstaller serviceInstaller = 
    new System.ServiceProcess.ServiceInstaller(); 
this.serviceInstaller.Description = "Handles Service Stuff"; 
+6

只需添加到这一点,你还可以设置 serviceInstaller.DisplayName = “一些好的显示名称”; – CapBBeard 2009-01-27 21:21:41

+0

exxelent。我正在考虑一些编码将需要ah-la这个解决方案... http://www.codeproject.com/KB/dotnet/dotnetscmdescription.aspx也许这只是VS2003所必需的? – 2009-07-20 01:26:35

1

你也可以创建一个的ServiceInstaller和服务安装程序的属性窗口中,您将看到您可以设置一个描述属性。如果你不想编码它。

+1

我很确定我尝试设置服务和服务安装程序中的每个描述属性,并且它们都没有工作。也许我错过了这一个。 – 2009-03-05 22:42:37

12

要如何做到这一点不使用代码澄清:

  • 添加一个服务安装到您的项目如下所述:http://msdn.microsoft.com/en-us/library/ddhy0byf%28v=vs.80%29.aspx

  • 打开在设计安装(如ProjectInstaller.cs)视图。

  • 单击服务安装程序组件(例如serviceInstaller1)或右键单击它并选择“属性”。

  • 在属性窗格中,设置Description和/或DisplayName(这也是您设置StartType等的地方)描述可能是您想要更改的所有内容,但如果您想给出稍微更易于理解的DisplayName (服务经理的第一列),你也可以这样做。

  • 如果需要,请打开自动生成的设计器文件(例如ProjectInstaller.Designer.cs)以验证属性设置是否正确。

  • 构建解决方案并使用installutil.exe或其他方法进行安装。

3

在创建在VS2010您的服务安装的项目,你需要一个覆盖添加到由VS创建为您服务描述注册表项类中的方法安装。

using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Configuration.Install; 
using System.ServiceProcess; 
using Microsoft.Win32; 

namespace SomeService 
{ 
    [RunInstaller(true)] 
    public partial class ProjectInstaller : System.Configuration.Install.Installer 
    { 
     public ProjectInstaller() 
     { 
      InitializeComponent(); 
     } 
     /// <summary> 
     /// Overriden to get more control over service installation. 
     /// </summary> 
     /// <param name="stateServer"></param>  
     public override void Install(IDictionary stateServer) 
     { 
      RegistryKey system; 

      //HKEY_LOCAL_MACHINE\Services\CurrentControlSet 
      RegistryKey currentControlSet; 

      //...\Services 
      RegistryKey services; 

      //...\<Service Name> 
      RegistryKey service; 

      // ...\Parameters - this is where you can put service-specific configuration 
      // Microsoft.Win32.RegistryKey config; 

      try 
      { 
       //Let the project installer do its job 
       base.Install(stateServer); 

       //Open the HKEY_LOCAL_MACHINE\SYSTEM key 
       system = Registry.LocalMachine.OpenSubKey("System"); 
       //Open CurrentControlSet 
       currentControlSet = system.OpenSubKey("CurrentControlSet"); 
       //Go to the services key 
       services = currentControlSet.OpenSubKey("Services"); 

       //Open the key for your service, and allow writing 
       service = services.OpenSubKey("MyService", true); 
       //Add your service's description as a REG_SZ value named "Description" 
       service.SetValue("Description", "A service that does so and so"); 
       //(Optional) Add some custom information your service will use... 
       // config = service.CreateSubKey("Parameters"); 
      } 
      catch (Exception e) 
      { 

       throw new Exception(e.Message + "\n" + e.StackTrace); 
      } 
     } 
    } 
} 

http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.aspx

http://www.codeproject.com/KB/dotnet/dotnetscmdescription.aspx

0

您也可以从IDE上ProjectInstaller类的设计视图中的“的ServiceInstaller”图标,将服务名称和说明,通过右键点击。

Setting service Description from IDE

相关问题