2009-01-27 61 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

相關問題