当用户从系统中卸载应用程序创建的日志文件时,如何删除该文件? [英] How to remove log files created by application when user uninstall it from the system?

查看:205
本文介绍了当用户从系统中卸载应用程序创建的日志文件时,如何删除该文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的Winforms应用程序在其执行过程中会创建一些日志文件.问题是,当用户从系统上卸载此应用程序时,该应用程序创建的所有文件夹和日志文件都保留在系统上.
是否有任何方法(在安装程序创建过程中或通过一些代码完成),通过卸载文件,我们可以删除应用程序创建的所有日志文件.

The Winforms application on which i am working creates some log files during its execution. The problem is when a user uninstall this application from the system, all the folders and log file created by the application remains on the system.
Is there any way(either during the creation of installer or thru some code) that with the uninstalltion of the file we can remove all the log files created by the application.

推荐答案

使用Visual Studio 2005/2008,您无需编写任何代码即可为安装程序项目添加卸载选项(是的,我知道有些人可以编写代码来实现此目的)

1)在安装项目中–>文件系统窗口->右键单击目标计算机上的文件系统" –>添加一个特殊文件夹,选择系统文件夹";

2)在这个系统文件夹中添加一个文件.从本地System32文件夹中浏览msiexec.exe并将其添加.覆盖此文件的默认属性,如下所示:

条件:=未安装(请确保您完全一样地放入未安装",包括大小写相同),
永久:= True,
系统:= True,
传递式:= True,
重要:= False.

3)在用户程序菜单"下创建一个新的快捷方式,将目标"设置为您在步骤1中创建的系统文件夹,并将其指向msiexec.exe.将快捷方式重命名为卸载应用程序".将Arguments属性设置为/x {space} [ProductCode].

5)构建项目,忽略有关应排除msiexec的事实的警告,不要将其排除,否则将不会建立安装项目.
Using Visual Studio 2005/2008, you don’t need to write any code to add a uninstall option for a Setup project (Yes I know some people can write code to do it)

1) In the Setup Project –> File System windows –> Right Click "File System on Target machine" –> add a Special Folder, select System Folder;

2) Into this system folder Add a file. Browse for msiexec.exe from local System32 folder and add it. Override default properties of this file as follows:

Condition:=Not Installed (make sure you put ‘Not Installed’ exactly like that, same case and everything),
Permanent:=True,
System:=True,
Transitive:=True,
Vital:=False.

3) Create a new shortcut under the ‘Users Program Menu’, Set Target to the System Folder which you created in the step 1. and point it’s at the msiexec.exe. Rename the shortcut to ‘Uninstall Your Application’. Set the Arguments property to /x{space}[ProductCode].

5) Build the project, ignore warning about the fact that msiexec should be excluded, DONT exclude it or the setup project wont build.


当已安装的应用程序创建日志文件或其他文件时,则在卸载过程中不会将其删除.在卸载期间,仅删除创建的文件和注册表项.
因此,要删除在程序执行期间创建的任何文件或数据,您需要创建一个自定义操作,该操作将在卸载过程中被调用.此自定义操作将删除应用程序将要创建的所有文件.

以下链接将帮助您创建自定义操作
Visual Studio设置项目中的自定义操作 [ ^ ]

http://www.simple-talk .com/dotnet/visual-studio/visual-studio-setup --- projects-and-custom-actions/ [
When the installed application creates a log file or some other files, then during uninstall it is not removed. During uninstall only the files and registry entries which are created gets deleted.
So for deleting any file or data which was created during program execution, you need to create a custom action which will be called during uninstall. This custom action will deleted all the files which is going to be created by application.

Following link will help you for creating custom action
Custom Action in Visual Studio setup projects[^]

http://www.simple-talk.com/dotnet/visual-studio/visual-studio-setup---projects-and-custom-actions/[^]


这篇关于当用户从系统中卸载应用程序创建的日志文件时,如何删除该文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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