[wix-users] Adding registry key upon Uninstall

Farrukh Waheed farrukh1 at gmail.com
Thu Nov 9 04:46:02 PST 2017


(Posted same on stack overflow

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="" Manufacturer="Testing"
        <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" />
        <Property Id="WixQuietExecCmdLine" Value=""[#RSS.cmd]"
        <CustomAction Id="SS" BinaryKey="WixCA" DllEntry="WixQuietExec"
Execute="deferred" Return="check"/>
          <Custom Action="SS" Before="RemoveFiles">Installed AND

        <Directory Id="TARGETDIR" Name="SourceDir">
          <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="RegOnUninstall" >
              <Component Id="RSS" Guid="*" >
                <File Id="RSS.cmd" KeyPath="yes"

**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 i.e.
can't write to HKLM.

**My main purpose is to write registry key upon Uninstall.**

Any help would be really appreciated....

More information about the wix-users mailing list