简体   繁体   中英

Wix: Adding registry keys on Uninstall

I'm given a requirement in which our installer has to restore/write a registry key upon uninstall/removal of the installer. To achieve this, I'm calling a .cmd file upon uninstall via Custom Action. Here is its code:

set SSKey=HKLM\Software\MyProduct\Installed Modules\TestModule
reg.exe add "%SSKey%" /v AppName  /d TestModule /f /reg:32
reg.exe add "%SSKey%" /v Type /t REG_DWORD /d 7 /f /reg:32
reg.exe add "%SSKey%" /v AppName  /d TestModule /f /reg:64
reg.exe add "%SSKey%" /v Type /t REG_DWORD /d 7 /f /reg:64

Here is the Custom Action snippet calling this .cmd file:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="RegOnUninstall" Language="1033" Version="1.0.0.0" Manufacturer="Testing" UpgradeCode="3dbec931-5475-40b3-a002-824c09aad36c">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" InstallPrivileges="elevated" />

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

    <Feature Id="ProductFeature" Title="RegOnUninstall" Level="1">
      <ComponentRef Id="RSS" />
    </Feature>
    <Property Id="WixQuietExecCmdLine" Value="&quot;[#RSS.cmd]&quot; -RSS"/>
    <CustomAction Id="SS" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Return="check"/>
    <InstallExecuteSequence>
      <Custom Action="SS" Before="RemoveFiles">Installed AND REMOVE</Custom>
    </InstallExecuteSequence>
 </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="RegOnUninstall" >
          <Component Id="RSS" Guid="*" >
            <File Id="RSS.cmd" KeyPath="yes" Source="D:\Scripts\RestSS.cmd"/>
          </Component>
        </Directory>
      </Directory>
    </Directory>
  </Fragment>

Note: This custom action is in WixUtilExtension.

Although installer is using Elevated Privileges, this script is not able to write in HKLM. Because of this failure, the installer is unable to Uninstall from the machine.

If I run this .cmd script in a Command Prompt with Admin privileges, it would work fine.

I tried to write Managed Custom Action and it was facing similar issue ie can't write to HKLM.

My main purpose is to write registry key upon Uninstall.

Any help would be really appreciated.... Thanks

您可能正在写HKLM ... 32位配置单元HKLM \\ SOFTWARE \\ Wow6432Node \\ My Product \\ My Company。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM