Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

c# - Custom Uninstall not deleting file in .net Application

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 SysWOW64AdvanceInstaller 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

File Removal


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...