2014-10-05 126 views
0

是否可以在不通過Installshield的情況下部署Windows服務?我有一個非常基本的服務,它只是簡單地探查數據庫,並希望將其部署到服務器上。在沒有Installshield的情況下部署Windows服務

我試過使用Installsheild LE,但在安裝時遇到錯誤1001,這很難排除故障,無論如何Installshield在這種情況下感覺像是矯枉過正......有沒有一種方法可以直接通過命令行或其他方式安裝服務方法?

回答

1

是的,如果你的服務有一個Installer類的話,你可以在命令行用installutil.exe

using System.ComponentModel; 
using System.Configuration.Install; 
using System.ServiceProcess; 

    [RunInstaller(true)] 
    public class ServiceInstaller : Installer 
    { 
     public ServiceInstaller() 
     { 
      ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller(); 
      ServiceInstaller serviceInstaller = new ServiceInstaller(); 

      //# Service Account Information 
      serviceProcessInstaller.Account = ServiceAccount.User; 
      serviceProcessInstaller.Username = ""; 
      serviceProcessInstaller.Password = ""; 

      //# Service Information 
      serviceInstaller.DisplayName = "Service name" 
      serviceInstaller.Description = "Service description" 
      serviceInstaller.StartType = ServiceStartMode.Automatic; 

      //# This must be identical to the WindowsService.ServiceBase name 
      //# set in the constructor of WindowsService.cs 
      serviceInstaller.ServiceName = "Service Name"; 

      this.Installers.Add(serviceProcessInstaller); 
      this.Installers.Add(serviceInstaller); 
     } 
    } 
3

是的。

不過,也有選擇,從最好到最差:

  1. 還有其他工具編寫安裝人員在那裏。例如。安裝Shield的完整版或WiX(由MS創建,並用於Visual Studio安裝程序)。

  2. 您可以使用installUtil已在您的程序集中包含衍生自ServiceInstaller的類型。 (請參閱How to: Install and Uninstall Service。)

  3. 您可以手動編輯註冊表。

#3是非常容易搞砸了,並不會幫助你記錄你應該包括的事件日誌和性能計數器。在開發過程中,#2是最好的,並且還會設置事件日誌和性能計數器(請記住,您需要提升安裝內容,並在作爲服務運行時將調試器附加到服務中)。

使用真正的安裝程序(#1)最適合測試(臨時)和生產環境。


,當你問爲什麼它不工作,你會希望能制定出發生了什麼事(或沒有)。

0

您可以使用命令行工具sc.exe來創建和配置Windows服務(基本上將配置插入到註冊表中),假設您已經將構建的.exe部署到您服務器上某處的磁盤。

http://support2.microsoft.com/kb/251192

相關問題