如何在卸载时删除应用程序文件夹

发布于 2024-12-02 11:07:59 字数 259 浏览 1 评论 0原文

  1. 我已经使用 VS 2010 中的安装项目创建了一个安装程序。它将我的应用程序安装到程序文件文件夹(比如说 XXX)中。我的应用程序进一步在 XXX 文件夹中创建一些文件和文件夹。卸载时,它会删除安装程序创建的所有内容,而我的应用程序创建的文件和文件夹保留在 XXX 中。

  2. 我编写了一些自定义代码来使用 installerclass 删除文件夹 (XXX),但当用户从控制面板卸载时不会执行,而当从我创建的安装程序卸载时成功执行。

  1. I have created a setup using Setup project in VS 2010. It install my application into program files folder lets say XXX. My application further creates some files and folder into XXX folder. At the time of uninstall it delete every thing whatever create by setup while files and folder created by my application remains there in XXX.

  2. I wrote some custom code to delete the folder (XXX) using installerclass but does not executes when user uninstall from control panel while executed successfully when uninstall from Setup created by me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

疧_╮線 2024-12-09 11:07:59

第一步是修改您的应用程序,以便将其数据写入每个用户的位置而不是应用程序文件夹。例如,您可以使用当前用户 AppData 目录中的自定义文件夹。这样您就可以避免与权限相关的问题。

要删除此文件夹,您确实可以使用自定义操作。如果将其添加到安装项目中的“卸载”下,则它应该针对控制面板和程序包卸载运行。

尝试创建详细卸载日志并搜索您的自定义操作名称以查看会发生什么情况。

The first step would be to modify your application so it writes its data in per-user locations instead of the application folder. For example, you can use a custom folder in the current user AppData directory. This way you avoid permission-related problems.

For removing this folder, you can indeed use a custom action. If it's added under Uninstall in your setup project, it should run for both Control Panel and package uninstalls.

Try creating a verbose uninstall log and search for your custom action name to see what happens.

断舍离 2024-12-09 11:07:59

我认为您不应该为此编写任何自定义代码,如果您的所有文件都标记为临时文件而不是永久文件,则这将由 MSI 引擎直接处理。

使用文件夹、文件和安装项目本身的配置和属性,您将获得所需的内容,而无需编写代码。

I don't think you should write any custom code for that, if all your files are marked as temporary and not permanent, this will be handled directly by the MSI engine.

Play with the configuration and properties of folders, files and the setup project itself and you will get what you need with no code to be written.

夏有森光若流苏 2024-12-09 11:07:59

我的猜测是,用于删除文件的自定义操作已安排在 UI 部分中。从控制面板启动卸载时,它会以最小 UI 模式运行,并且会跳过所有对话框。

您的自定义操作必须安排在 InstallExecute 表中。
(为了与 UAC 兼容,必须使用 noimpersonate延迟。但是您的应用程序本身与 UAC 不兼容,所以这并不重要。)

My guess is that your Custom Action for removing files is scheduled in UI section. When uninstall is started from Control Panel, it runs in minimal UI mode, and all your dialogs are skipped.

Your Custom Action must be scheduled in InstallExecute table.
(To be compatible with UAC, it must be deferred with noimpersonate. Yet your application itself is not compatible with UAC, so it does not really matter.)

青丝拂面 2024-12-09 11:07:59

不要这样做!首先,用户通常不喜欢在没有警告的情况下删除他们放在应用程序目录中的数据文件(他们可能只是卸载它,因为他们想将其移动到不同的位置)例如,开车)。最好让最终用户根据需要手动删除它们。另外,如果用户错误地将程序安装在错误的目录中(例如C:\WINDOWS),然后又卸载它,则可能会造成灾难性的后果。或者,如果用户将他珍贵的色情视频隐藏在应用程序文件夹中怎么办?再次强调,不要这样做!

DON'T DO THIS! First, users usually don't appreciate having their data files they put in the application directory deleted without warning (they might only be uninstalling it because they want to move it to a different drive, for example). It's better to leave it up to the end users to manually remove them if they want. Also, if the user happened to install the program in the wrong directory by mistake (for example, C:\WINDOWS) and then went to uninstall it there could be disastrous consequences. Or what if the user hides his precious porn videos inside the application folder? So again, DON'T DO THIS!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文