I have created installer which needs to delete some files and folder if they already exists and replace with new one.
When the user clicks on install, the installer prompts for UAC. On selecting Yes, the installer will call the method to delete existing files and folder. But it is unable to delete the files and folder. Code I am using is DI.Delete(path). It gives this error
Access to the path 'CodeCreate.aspx' is denied.
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive)
at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive)
at System.IO.DirectoryInfo.Delete(Boolean recursive)
at CustomizationCA.CustomActions.DeleteExistingFilesAndFolder(Session session)
While if I run command prompt as administrator and then using "msiexec /i Setup.msi" command, it deletes those files and folder.
And when using Directory.Delete(path,true); I am getting this as exception
Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.
at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String machineName)
at System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName)
at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte rawData)
at System.Diagnostics.EventLog.WriteEntry(String source, String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte rawData)
at System.Diagnostics.EventLog.WriteEntry(String source, String message)
at CustomizationCA.CustomActions.DeleteExistingFilesAndFolder(Session session)
I am using WIX tool to create installer.
If I go to properties of particular file and then give full permission to all users and then try to delete the file, the file is getting deleted.