[wix-users] Adding registry key upon Uninstall

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


Hi,

(Posted same on stack overflow
<https://stackoverflow.com/questions/47202180/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=""[#RSS.cmd]"
-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 i.e.
can't write to HKLM.

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

Any help would be really appreciated....
Thanks


More information about the wix-users mailing list