WiX在卸载时删除LocalAppData(AppData \ Local \ my_app_folder) [英] WiX remove LocalAppData (AppData\Local\my_app_folder) on uninstall

查看:242
本文介绍了WiX在卸载时删除LocalAppData(AppData \ Local \ my_app_folder)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个wix安装项目,该项目创建一个ProgramMenu快捷方式和一个Desktop快捷方式.我可以使用 RemoveFolder 删除这些快捷方式.

I have a wix setup project which creates a ProgramMenu shortcut and a Desktop shortcut. I am able to remove these shortcuts by using RemoveFolder.

<!-- To remove Desktop shortcut -->
<RemoveFolder Id="RemoveDesktopFolder" Directory="DesktopFolder" On="uninstall"/>

<!-- To remove ProgramMenu shortcut-->
<RemoveFolder Id="CleanUpShortCut" Directory="ApplicationProgramsFolder" On="uninstall" />

但是,在卸载时,我还希望能够清除当前用户的

However, on uninstall, I also want to be able to clear the current user's LocalAppData. More specifially, Users\CurrentUser\AppData\Local\my_application

到目前为止,我发现 RemoveFolder 不会递归删除文件,因此我必须使用 util:RemoveFolderEx .这是我的方法:

So far, I have figured out that the RemoveFolder does not remove files recursively and that I would have to use util:RemoveFolderEx. This is how I have done it:

  <Directory Id="LocalAppDataFolder" Name="Local">
    <Directory Id="RemoveLocalData" Name="my_application">
      <Component Id="RemoveLocalAppData" Guid="PUT-GUID-HERE">
        <util:RemoveFolderEx On="uninstall" Property="RemoveLocalData"/>
        <RemoveFolder Id="RemoveLocalData" On="uninstall"/>
      </Component>
    </Directory>
  </Directory>

我收到此错误:
ICE38: 组件RemoveLocalAppData安装到用户配置文件.它必须使用 HKCU下的注册表项作为其KeyPath,而不是文件.

And I get this error:
ICE38: Component RemoveLocalAppData installs to user profile. It must use a registry key under HKCU as its KeyPath, not a file.

我认为我没有正确使用 RemoveFolderEx ,但是在这种情况下,我不知道清除LocalAppData的正确方法.

I figure I am not using RemoveFolderEx properly, but I do not know the right way in this case to clear my LocalAppData.

注意,我在安装过程中没有创建该文件夹.相反,此[LocalAppData] \ my_application是在安装后由应用程序在运行时创建的.

Note, I do not create the folder during installation. Instead, this [LocalAppData]\my_application is created post-installation at run-time by the application.

推荐答案

在以下链接的帮助下,最终设法删除了当前用户的LocalAppData(cache): https://pkisensee.wordpress.com/2015/10/06/windows-installer-removing-folders/

Finally managed to delete current user's LocalAppData(cache) with help from the following the link: https://pkisensee.wordpress.com/2015/10/06/windows-installer-removing-folders/

为了成功删除应用程序的LocalAppData文件夹,我将不得不在注册表中(使用 RegistrySearch )搜索应用程序缓存文件夹的位置,并将其存储在 Property 中. strong>.

In order to successfully delete the application's LocalAppData folder, I would have to search the registry (using RegistrySearch) for the location of the application cache folder and store it in a Property.

<Property Id="CACHEFOLDER">
     <RegistrySearch Key="Software\CompanyName\AppName" Root="HKCU" Type="raw"
                     Id="CacheFolderRegSearch" Name="CachePath" />
</Property>

但是,此注册表项目前不存在,并且路径也无法解析.因此,在安装过程中,我必须将LocalAppData缓存文件夹的位置保存在注册表中,以便在卸载时,可以执行 RegistrySearch 并通过 util:RemoveFolderEx <递归删除缓存文件夹. /strong>.

However, at the moment this registry entry does not exist, and the path would not be resolved. Hence during installation, I have to save the location of the LocalAppData cache folder in the registry, so that on uninstall, I can do a RegistrySearch and remove the cache folder recursively by util:RemoveFolderEx.

为此,我在组件中将 RegistryValue 设置为:

To do that, I set the RegistryValue in a component as such:

<Directory Id="TARGETDIR" Name="SourceDir">

    <!-- ... -->

    <!-- This is the name of the cache folder in LocalAppData -->
    <!-- In this case the cache folder is in \Users\CurrentUser\AppData\Local\MyAppCache -->
    <?define AppCacheFolder = "MyAppCache" ?>
    <Component Id="CacheCleanup" Guid="*">
         <RegistryValue Root="HKCU" Key="Software\CompanyName\AppName" Name="CachePath" 
                        Type="string" Value="[LocalAppData]$(var.AppCacheFolder)"                   
                        KeyPath="yes" />
         <util:RemoveFolderEx On="uninstall" Property="CACHEFOLDER"/>
    </Component>

    <!-- ... -->

</Directory>

请注意,这是在 TARGETDIR 目录

最后,需要将该组件注册到功能

And finally, need to register that component into a Feature

<Feature Id="MainApplication" Title="App Name" Level="1">
    <!-- Other Components -->
    <ComponentRef Id="CacheCleanup" />
</Feature>

这篇关于WiX在卸载时删除LocalAppData(AppData \ Local \ my_app_folder)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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