用户卸载时停止和卸载其他服务

时间:2013-04-26 18:21:43

标签: windows-services wix wix3

是否有检查服务是否已安装,如果是,请在使用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打印机服务”,它都能正常工作。我喜欢简单的解决方案!

1 个答案:

答案 0 :(得分:2)

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

<ServiceControl Id='NukeService' Name='YourServiceName'
                Remove='uninstall' Stop='uninstall' />