Custom Uninstall not deleting file in .net Application

女生的网名这么多〃 提交于 2020-02-06 11:22:16

问题


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);
        }

   }

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.

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.

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

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

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


回答1:


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".



来源:https://stackoverflow.com/questions/53370821/custom-uninstall-not-deleting-file-in-net-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!