WiX RemoveRegistryKey元素的行为与广告不符 [英] WiX RemoveRegistryKey element not behaving as advertised

查看:87
本文介绍了WiX RemoveRegistryKey元素的行为与广告不符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在卸载时似乎无法删除注册表项.请注意,这不是这个问题的重复,因为我不这样做.认为我也有同样的问题.或者,如果我愿意,我想澄清原因.当我在新的VM上安装时会发生此问题,所以这与在同一GUID上安装不一样.

I can't seem to delete a registry key when I uninstall. Note that this isn't a repeat of this question, as I don't think that I have the same problem. Or, if I do, I'd like some clarification as to why. This problem happens when I install on a fresh VM, so it's not like I'm installing on top of the same GUID.

我正在做的是将来自用户的值(从UI)放入某些属性,然后通过 CustomAction 将其导入到C#代码中,然后在其中加密值并将其放入注册表项.

What I'm doing is placing values from the user (from a UI) into some properties, importing those into some C# code through a CustomAction, where I then encrypt the values and put them into a registry key.

我不使用WiX将值放入注册表项,而是通过C#代码来完成.原因是我似乎无法将Properties导入到C#自定义操作中,然后再将同一代码中的值导出回WiX中(我可以分别完成每个操作,都没有问题).但这是一个不同的问题...

I don't use WiX to put the values into the registry key, I do it from the C# code. The reason for this is I can't seem to import Properties into a C# Custom Action and then export values from that same code back into WiX (I can do each separately no problem). But that's a different question...

无论如何,我都会获取值,对其进行加密,然后将它们放入注册表项中就可以了.我只是似乎无法在卸载时删除注册表项.奇怪的是,它不会删除键中的每个值(除了一个),但不会删除整个键.

Anyways, I get the values, encrypt them, and place them into a registry key just fine. I just can't seem to delete the registry key when uninstalling. Oddly enough, it does delete every value in the key except for one, but it doens't delete the entire key.

以下是应该删除密钥的XML(但不是):

Here's the XML that should delete the key (but doesn't):

        <Component Id="Component_CleanRegistryOnUninstall"
               Directory="TARGETDIR"
               Guid="{86D04E28-2EF8-4A6C-BB9B-577EA1597BB5}" 
               KeyPath="yes">
        <RemoveRegistryKey Id="CleanupRegistry"
                           Root="HKLM"
                           Key="Software\...\...\InstallCfg"
                           Action="removeOnUninstall"/>
        </Component>

以下是创建C#自定义操作的XML:

Here's the XML that creates the C# Custom Action:

    <Fragment>      
  <Property Id="VAL1" Hidden="yes"/>
  <Property Id="VAL2" Hidden="yes"/>
  <Property Id="VAL3" Hidden="yes"/>
  <Property Id="VAL4" Hidden="yes"/>

  <SetProperty Id="CustomAction_PassProperty"
               Value="VAL1=[VAL1];VAL2=[VAL2];VAL3=[VAL3];VAL4=[VAL4]"
               Sequence="execute"
               Before="CustomAction_PassProperty"/>

  <Binary Id="Binary_PassProps"
          SourceFile="$(var.CreateRegistryKey.TargetDir)CreateRegistryKey.CA.dll"/>

  <!-- Note that 'Impersonate="no"' elevates the privilege of the C# code, needed to create keys -->
  <CustomAction Id="CustomAction_PassProperty"
                BinaryKey="Binary_PassProps"
                DllEntry="CreateKeys"
                Execute="deferred"
                Impersonate="no"
                Return="check" 
                HideTarget="yes"/>

  <InstallExecuteSequence>
      <Custom Action="CustomAction_PassProperty"
              After="InstallInitialize"/>
  </InstallExecuteSequence>
</Fragment>

这是C#本身:

        [CustomAction]
    public static ActionResult CreateKeys(Session session)
    {
        // encrypt and set set the registry keys
        Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\...\\...\\InstallCfg", "Val1", Encrypt(session.CustomActionData["VAL1"]));
        Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\...\\...\\InstallCfg", "Val2", Encrypt(session.CustomActionData["VAL2"]));
        Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\...\\...\\InstallCfg", "Val3", Encrypt(session.CustomActionData["VAL3"]));
        Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\...\\...\\InstallCfg", "Val4", Encrypt(session.CustomActionData["VAL4"]));

        // also, set the "SettingsProcessed" key to false
        Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\...\\...\\InstallCfg", "SettingsProcessed", "false");

        return ActionResult.Success;
    }

设置的最终值(只是作为"false"而不是加密值传入的值)是一个标志,并且可能是问题的关键.

The final value that is set -- the one that is just passed in as "false" and not an encrypted value -- is a flag, and may be the key to the problem.

这是一种奇怪的行为:当我卸载时,密钥没有被删除,但是它确实删除了所有的值除了,一个不是传递给C#函数的标志.它没有被删除.但是,即使我创建了一个属性,也要给该属性指定值"false",然后将其传递给C#,如下所示:

Here's the weird behavior: when I uninstall, the key doesn't get deleted, but it does delete all of the values except the one value that isn't passed into the C# function, the flag. It's not getting deleted. However, even if I create a property, give that property the value "false", and pass it into the C#, like this:

Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\...\\...\\InstallCfg", "SettingsProcessed", session.CustomActionData["SETTINGSPROCESSED"]);

发生同样的事情:除此以外的所有其他值都会被删除.我承认这可能是组件问题,答案可能在答案,但我不知道.

The same thing happens: every other value gets deleted except for it. I admit that it may be a Component issue and the answer may lie in this answer, but I can't figure it out.

总结:注册表项已创建,但<RemoveRegistryKey>并未在卸载后删除它.

To sum up: the registry key gets created but the <RemoveRegistryKey> doesn't delete it upon uninstallation.

:

:

Bob从来没有使用过他的<RemoveRegistryKey>元素.他退出IT部门,搬到奥马哈,在那里经营一家黎巴嫩/荷兰披萨店并练习班卓琴.

Bob never got his <RemoveRegistryKey> element to work. He quit IT and moved to Omaha, where he runs a Lebanese/Dutch pizza shop and practices the banjo.

不,真的,我从来没有使它起作用.我最终创建了另一个自定义操作,该操作删除了密钥.真令人沮丧,让我想搬到奥马哈.

No, really, I never got it to work. I ended up creating another Custom Action that deletes the key. It's so frustrating it makes me want to move to Omaha.

推荐答案

您需要设置一个条件,以在卸载期间不运行CustomAction_PassProperty. 像这样:

You need to set a condition to not run CustomAction_PassProperty during uninstallation. Like this:

  <InstallExecuteSequence>
      <Custom Action="CustomAction_PassProperty"
              After="InstallInitialize>NOT REMOVE="ALL"</Custom>
  </InstallExecuteSequence>

除硬编码外,它删除所有值"可能是由于您在卸载过程中重写了VAL1, VAL2...的值而导致的,此时这些属性可能为空(它们仅在ui的安装过程中设置)顺序正确吗?).

That it "deletes all the values" except for the hardcoded one could be a result of you rewriting the values of VAL1, VAL2... during uninstall, at which time those properties likely are empty (they are set only during install in the ui sequence right?).

这篇关于WiX RemoveRegistryKey元素的行为与广告不符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆