【问题标题】:Deploy a windows service without Installshield在没有 Installshield 的情况下部署 Windows 服务
【发布时间】:2014-10-05 09:05:21
【问题描述】:

是否可以在不通过 Installshield 的情况下部署 Windows 服务?我有一个非常基本的服务,它只是探测数据库,并希望将其部署在服务器上。

我尝试使用 Installsheild LE,但安装时出现错误 1001,这很难解决,无论如何 Installshield 在这种情况下感觉有点过头了...有没有办法可以直接通过命令行或其他方法安装服务?

【问题讨论】:

    标签: visual-studio-2012 windows-services installshield


    【解决方案1】:

    是的。

    但是,有一些选项,从最好到最差:

    1. 还有其他用于编写安装程序的工具。例如。 install Shield 的完整版或WiX(由 MS 创建,用于 Visual Studio 安装程序)。

    2. 您可以使用 installUtil 并在您的程序集中包含派生自 ServiceInstaller 的类型。 (见How to: Install and Uninstall Service。)

    3. 您可以手动编辑注册表。

    #3 非常容易搞砸,不会帮助您处理应该包括的事件日志记录和性能计数器。1 #2 是开发中最好的,并且会设置事件日志和性能计数器(请记住,您需要升级才能安装东西,并在作为服务运行时将调试器附加到服务)。

    在测试(暂存)和生产环境中最好使用真正的安装程序(#1)。


    1当你被问到为什么它不起作用时,你会希望能够弄清楚发生了什么(或没有发生)。

    【讨论】:

      【解决方案2】:

      是的,如果您的服务有 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】:

        Building and Deploying a Windows Service using IsWiX

        以上是我制作的一个简短视频,展示了如何使用 WiX / IsWiX 生成非常干净的 MSI 以安装服务。它非常简单、快速、优雅且免费。

        【讨论】:

          【解决方案4】:

          您可以使用命令行工具 sc.exe 创建和配置 Windows 服务(基本上将配置插入注册表),假设您已经将构建的 .exe 部署到磁盘的某个位置服务器。

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

          【讨论】:

            猜你喜欢
            • 2011-08-02
            • 2021-05-12
            • 1970-01-01
            • 1970-01-01
            • 2011-02-20
            • 2016-02-04
            • 1970-01-01
            • 2010-09-07
            • 2010-09-20
            相关资源
            最近更新 更多