1

无论如何要检查是否安装了服务,如果是,请在使用 WiX 3.7 卸载我的应用程序时停止并卸载它?不过,我不希望 WiX 安装该服务 - 只需将其卸载即可。

我有 WiX 设置来安装多个应用程序组件,但应用程序本身可以生成 Windows 服务(取决于安装期间选择的功能)。我不确定清理它的最佳方法是什么 - 我想只是让我的设置检查该服务是否存在并在卸载时将其删除。

我不确定我是否需要 CustomAction。我对使用 WiX 安装服务非常熟悉,但不仅仅是删除它们(如果存在的话)。

这是我的设置项目。只是为了提供一些额外的背景知识,这是一个自动更新器/启动器应用程序。它需要一系列 XML 文件来告诉它如何更新/准备应用程序。例如,如果您选择“MyApp Printer”功能,它将安装一个额外的 XML 文件,告诉我的应用程序如何根据 Web 服务对本地文件进行哈希检查,然后为该组件安装并启动“MyApp Printer”Windows 服务. 位于我的实际 WiX 安装项目中的 Windows 服务是完全不同的,卸载时工作正常,所以请忽略那个。

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="MyApp ID" Language="1033" Version="1.0.0.0" Manufacturer="MyApp ID" UpgradeCode="932dbe1f-e112-4bd0-8f60-b81850fb465b">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />

    <WixVariable Id="WixUILicenseRtf" Value="EULA.rtf" />

    <Feature Id="ProductFeature" Title="MyApp ID Setup Core" Level="1" Absent="disallow" Display="expand">
      <ComponentGroupRef Id="ProductComponents" />
      <ComponentRef Id="MyAppStartMenuFolderRemove" />

      <Feature Id="MyAppClientFeature" Title="MyApp ID Windows Client" Level="1" Absent="allow">
        <ComponentGroupRef Id="MyAppClientComponents" />
        <ComponentRef Id="MyAppStartMenuIcon" />
      </Feature>

      <Feature Id="MyAppPrinterFeature" Title="MyApp ID Printer App" Level="2" Absent="allow">
        <ComponentGroupRef Id="MyAppPrinterComponents" />
        <ComponentRef Id="PrinterStartMenuIcon" />
      </Feature>
    </Feature>


    <UIRef Id="WixUI_FeatureTree" />
    <UIRef Id="WixUI_ErrorProgressText" />
  </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="MyAppBaseFolder" Name="MyAppID">
          <Directory Id="INSTALLFOLDER" Name="MyAppLauncher">
            <Directory Id="UPDATESCRIPTSFOLDER" Name="Scripts" />
          </Directory>
        </Directory>
      </Directory>
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="MyApp ID"/>
      </Directory>
    </Directory>
  </Fragment>

  <Fragment>
    <DirectoryRef Id="ApplicationProgramsFolder">
      <Component Id="PrinterStartMenuIcon">

        <Shortcut Id="PrinterStartMenuShortcut"
                  Name="MyApp ID Printer UI"
                  Description="Manage the MyApp ID Printer Service"
                  Icon="MyAppPrinterIcon"
                  Target="[INSTALLFOLDER]AutoUpdater.exe"
                  Arguments="MyAppPrinter"
                  WorkingDirectory="INSTALLFOLDER">
          <Icon Id="MyAppPrinterIcon" SourceFile="$(var.AutoUpdater.Launcher.TargetDir)\Resources\MyApp_printer_white.ico" />
        </Shortcut>

        <RegistryValue Root="HKCU" Key="Software\Microsoft\MyApp.CardPrinter.Service" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
      <Component Id="MyAppStartMenuIcon">
        <Shortcut Id="MyAppStartMenuShortcut"
                  Name="MyApp ID"
                  Description="Run the MyApp ID Windows Client software"
                  Target="[INSTALLFOLDER]AutoUpdater.exe"
                  Arguments="MyAppClient"
                  WorkingDirectory="INSTALLFOLDER"/>

        <RegistryValue Root="HKCU" Key="Software\Microsoft\MyApp.WindowsClient" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
      <Component Id="MyAppStartMenuFolderRemove">
        <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
        <RegistryValue Root="HKCU" Key="Software\Microsoft\MyApp.WindowsClient" Name="installedFolder" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
    </DirectoryRef>
  </Fragment>


  <Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <Component Id="LibrariesComponent" Guid="7ED3B3B3-A984-44ED-9BA3-841F53CEA114">
        <File Source="$(var.AutoUpdater.Foundation.TargetPath)" Vital="yes" KeyPath="yes" />
        <File Source="$(var.AutoUpdater.Module.TargetPath)" Vital="yes" />
        <File Source="$(var.AutoUpdater.Module.WebService.TargetPath)" Vital="yes" />
      </Component>
      <Component Id="ServiceComponent" Guid="CAB8D997-5798-4B9D-8CA0-78AACE58932E">
        <File Source="$(var.AutoUpdater.Service.TargetPath)" Vital="yes" KeyPath="yes" />
        <File Source="$(var.AutoUpdater.Service.TargetDir)\AutoUpdater.Service.exe.config" Name="AutoUpdater.Service.exe.config" Vital="yes" />
        <ServiceInstall Name="ServiceComponentInstall" Id="ServiceComponentInstall" DisplayName="MyApp ID Launcher" Account="LocalSystem" ErrorControl="normal" Type="ownProcess" Start="auto" Vital="yes" />
        <ServiceControl Name="ServiceComponentInstall" Id="ServiceComponentControl" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
      </Component>
      <Component Id="LauncherComponent">
        <File Source="$(var.AutoUpdater.Launcher.TargetPath)" Vital="yes" />
        <File Source="$(var.AutoUpdater.Launcher.TargetDir)\Resources\MyApp_printer_white.ico" Name="MyApp_printer_white.ico" />
      </Component>
    </ComponentGroup>
  </Fragment>

  <Fragment>
    <ComponentGroup Id="MyAppClientComponents" Directory="UPDATESCRIPTSFOLDER">
      <Component Id="MyAppClientXml">
        <File Source="$(var.AutoUpdater.Service.TargetDir)\Scripts\MyAppClient.xml" Name="MyAppClient.xml" />
      </Component>
    </ComponentGroup>
  </Fragment>

  <Fragment>
    <ComponentGroup Id="MyAppPrinterComponents" Directory="UPDATESCRIPTSFOLDER">
      <Component Id="MyAppPrinterXml">
        <File Source="$(var.AutoUpdater.Service.TargetDir)\Scripts\MyAppPrinter.xml" Name="MyAppPrinter.xml" />
      </Component>
    </ComponentGroup>
  </Fragment>
</Wix>

我希望这不会太令人困惑:)。提前致谢!

编辑:

谢谢 Rob,解决方案是将<ServiceControl>元素添加到最后一个片段:

  <Fragment>
    <ComponentGroup Id="MyAppPrinterComponents" Directory="UPDATESCRIPTSFOLDER">
      <Component Id="MyAppPrinterXml">
        <File Source="$(var.AutoUpdater.Service.TargetDir)\Scripts\MyAppPrinter.xml" Name="MyAppPrinter.xml" />
        <ServiceControl Id="NukeMyAppPrinterService" Name="MyApp ID Printer Service" Remove="uninstall" Stop="uninstall" />
      </Component>
    </ComponentGroup>
  </Fragment>

无论是否安装了“MyApp ID 打印机服务”,它都可以工作。我喜欢简单的解决方案!

4

1 回答 1

2

不能说我自己已经完成了(这是一个非常独特的场景),但该ServiceControl元素应该可以很好地完成工作:

<ServiceControl Id='NukeService' Name='YourServiceName'
                Remove='uninstall' Stop='uninstall' />
于 2013-04-26T19:00:24.027 回答