问题
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