自定义卸载不删除 .net 应用程序中的文件 [英] Custom Uninstall not deleting file in .net Application

查看:30
本文介绍了自定义卸载不删除 .net 应用程序中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用户运行 wpf 应用程序时创建了一个设置文件.我创建了一个自定义卸载程序来删除与我的应用程序相关的一些注册表项并删除此设置文件.但是我的文件没有被删除.这是代码 -

I have a settings file created when user run the wpf application. I have created a custom uninstaller to delete some registry keys related to my app and to delete this setting file. But my file is not getting deleted. Here is the code -

 public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);

        try
        {
            using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
            {

                if (registryKey.GetValue("TeachingManagementTool") != null)
                {
                    registryKey.DeleteValue("TeachingManagementTool", true);
                }                    
            }
            if (File.Exists("Setting.ini"))
                File.Delete("Setting.ini");
        }
        catch (Exception ex)
        {
            MessageBox.Show("Registry Keys  exception " + ex.Message);
        }

   }

我尝试了 Directory.GetCurrentDirectory() 来获取文件名并删除它,但它不起作用.所以我检查了这行代码作品 file.Delete(filename).它删除指定的文件.所以它应该在卸载过程中删除该文件,因为它在同一文件夹中.

I tried Directory.GetCurrentDirectory() to get file names and delte it, but it doesnt work. So I checked this line of code works file.Delete(filename). It delets the specified file. So it should delete the file during uninstall as its in the same folder.

最后我应该说 - 我尝试了 2-3 种不同的方法来访问该文件并在卸载过程中将其删除.但它有时不会删除和抛出错误,有时根本没有例外.

At the end I should say- I tried 2-3 different ways to access that file and delete it during uninstallation. but Its not delteting and throwing error some times and sometimes no exception at all.

异常与访问 SysWOW64\AdvanceInstaller 相关是拒绝

The exception was related to Access to SysWOW64\AdvanceInstaller is denied

仅供参考 - 我的应用程序已经 <requestedExecutionLevel level="highestAvailable" uiAccess="false"/>.

FYI - MY App has <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> already.

我尝试了 StackOverflow 上提供的解决方案,但它不起作用所以我需要提出一个新问题.所以请让我知道我错在哪里.我敢肯定,我在这里可能会遗漏一些非常小的东西

I tried solutions available on StackOverflow but its not working So I needed to ask a new question. So please let me know where I am mistaking. I am sure it is something very minor that I might be missing here

推荐答案

Advanced Installer:所以你在使用Advanced Installer?在文件和文件夹视图中,选择有问题的目标文件夹.在右侧窗格中,右键单击要删除的文件所在的文件夹.您看到新建文件操作"了吗?选择文件删除"并配置选项.

Advanced Installer: So you are using Advanced Installer? In the Files and Folders view, select the destination folder in question. In the right pane, right click inside the folder where the file to remove resides. Do you see "New File Operation"? Select "File Removal" and configure options.

记得正确设置选项.特别是删除".选择组件卸载".

Remember to set the options properly. In particular "Remove On". Select on "Component Uninstall".

这篇关于自定义卸载不删除 .net 应用程序中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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