在卸载功能之前删除文件 [英] delete a file before uninstall function

查看:100
本文介绍了在卸载功能之前删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个win应用程序,它在运行时在自己的setup文件夹路径中创建一个xml文件。我已经为我的应用程序创建了一个设置,但我不知道如何在卸载应用程序之前删除该xml文件!!!



我试过安装程序类但它没有奏效。我认为问题是在BeforeUninstall事件中,应用程序的安装文件夹路径被处理掉。



注意:我使用以下代码查找安装文件夹我的申请..



Hi everyone,
I have a win application that creates a xml file in runtime in the setup folder path of itself. I have created a setup for my application, but i do not know how can i delete that xml file before the application is uninstalled!!!

I have tried Installer class but it did not worked. I think the problem is that in BeforeUninstall event of it the setup folder path of the application is disposed.

Note : I have used the following code to find the setup folder of my application..

using Microsoft.Win32;

RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Installer\Assemblies");
string regfilepath="";
if (key!=null)       // Make sure there are Assemblies
{
    foreach(string Keyname in key.GetSubKeyNames())
    {
        if (Keyname.IndexOf("YOUR_EXE_FILE.EXE")>0)
        {
    regfilepath=Keyname;
    break;
        }
   }
}
string fullpath="";
for (int a=0;a<regfilepath.Length;a++)
{
  if (regfilepath.IndexOf("|",a,1)>0)
   fullpath+="\\";
 else
  fullpath+=regfilepath.Substring(a,1);
}

推荐答案

我不认为你有什么可能做的但是我想要一个解决方法:

你不能把文件写到AppData文件夹吗?然后你应该能够在安装程序的BeforeUninstall或AfterInstallFinished事件中删除AppData文件夹中的文件或文件夹。



欢呼,

Marco Alessandro Bertschi
I don''t think that it is possible what you are trying to do but I imagine a workaround:
can''t you write the file to the AppData folder? Then you should be able to delete the file or folder in the AppData folder in the BeforeUninstall or AfterInstallFinished event of your installer.

cheers,
Marco Alessandro Bertschi


这篇关于在卸载功能之前删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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