【问题标题】:how to use MSI to update a service如何使用 MSI 更新服务
【发布时间】:2011-07-16 04:45:07
【问题描述】:

我使用 MSI 安装程序安装了 Windows 服务。我试图让这个安装程序充当“更新程序”,首先让它自行卸载(RemovePreviousVersions=true ?)然后重新安装。我理解的方式是,使用 RemovePreviousVersions=true,当安装程序第二次运行时,它应该注意到产品的当前版本与安装的版本不同,它会对已安装的产品执行卸载操作,然后执行在新版本上安装操作。然而,情况似乎并非如此。似乎初始卸载步骤从未发生,安装程序只是尝试执行安装。这引起了我的问题,因为安装程序自定义操作是服务安装,当然,服务已经安装,然后抱怨“服务已经存在”。

如何让 Windows 安装程序先卸载然后安装服务?也许我对 MSI 安装程序如何工作的理解是错误的?有没有更好的方法来安装服务?

【问题讨论】:

    标签: windows-installer


    【解决方案1】:

    这是我的做法。

    设置升级 ID GUID(必须在安装过程中保持不变):

    <?define ProductVersion="3.0.43.0" ?>
    <?define UpgradeCode="{3F198E84-0BB6-4765-B48A-64DE5F8C4A65}" ?>
    
    <Product Id='*' Name='...' Language='1033'
             Version='$(var.ProductVersion)' Manufacturer='...'
             UpgradeCode='$(var.UpgradeCode)'>
    
    
    <Property Id='PREVIOUSVERSIONSINSTALLED' Secure='yes'/>
    <Upgrade Id='$(var.UpgradeCode)'>
      <UpgradeVersion Minimum='1.0.0.0'
                      Maximum='$(var.ProductVersion)'
                      IncludeMinimum='yes'
                      IncludeMaximum='no'
                      Property='PREVIOUSVERSIONSINSTALLED'/>
    </Upgrade>
    

    然后在服务器组件标签里面:

    <ServiceInstall Id='server.exe' Name='...' DisplayName='...' Type='ownProcess'
                    Interactive='no' Start='auto' Vital='yes' ErrorControl='normal'
                    Account='LocalSystem'
    </ServiceInstall>
    <ServiceControl Id='server_start' Name='...' Start='install' Wait='yes' />
    <ServiceControl Id='server_stop' Name='...' Stop='both' Wait='yes' />
    <ServiceControl Id='server_remove' Name='...' Remove='uninstall' Wait='yes' />
    

    这会停止正在运行的服务,将其删除,安装新服务并重新启动。

    最后:

    <InstallExecuteSequence>
      <LaunchConditions After='AppSearch' />
      <RemoveExistingProducts After='InstallInitialize' />
    </InstallExecuteSequence>
    

    【讨论】:

    • 可以将三个ServiceControl元素合二为一——&lt;ServiceControl Id="StartStopRemove" Name="..." Start="install" Wait="yes" Stop="both" Remove="uninstall" /&gt;
    • 这绝对有帮助。我忘了提到我们目前没有 WIX。我可能需要考虑改用 Wix
    【解决方案2】:

    您在执行序列中的何处安排了 RemoveExistingProducts?行为基于此而变化。请参阅操作说明 - http://msdn.microsoft.com/en-us/library/aa371197%28v=vs.85%29.aspx

    【讨论】:

      猜你喜欢
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-31
      • 2019-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多