I have an exe runs in C:\ProgramFiles\MyAPP\MyApplication.exe and this app runs at startup
(HKLM: SOFTWARE\Microsoft\Windows\CurrentVersion\Run) The SQLite database and other configuration files located at C:\ProgramData\MyAppSettings Folder
I’m installing the application using Inno Setup and I have set ProgramData\MyAppSettings folder permission to users-full by using this code snippet.
[Dirs]
Name: "{commonappdata}\MyAppSettings"; Permissions: users-modify users-full
I have a updater.exe too which downloads the latest updates (as 2 zip files) and extracts them to Program Files and ProgramData folders.
The workflow of this update process is like this.
UAC and Launch updater.exe as Administrator. Then terminate the MyApplication.exeAll those things work fine except one thing.
After updater.exe extract, the zip file on ProgramData the MyApplication.exe cannot access files on it
System.UnauthorizedAccessException: 'Access to the path 'C:\ProgramData\MyAppSettings\Database.db' is denied.
So I have tried something like this.
Before the updater.exe terminate, it grant access permission to Everyone Full Control
Private Sub GrantAccessPermission(ByVal fullPath As String)
Dim dInfo As DirectoryInfo = New DirectoryInfo(fullPath)
Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
dSecurity.AddAccessRule(New FileSystemAccessRule(New SecurityIdentifier(WellKnownSidType.WorldSid, Nothing), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit Or InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow))
dInfo.SetAccessControl(dSecurity)
End Sub
Unfortunately, the result is the same. MyApplication.exe still cannot access files in the ProgramData. Where could the problem be?
Folder and database file permission

what updater.exe doing in the ProgramData folder
Using Zip As New Ionic.Zip.ZipFile(BaseCompSource)
Dim Entry As ZipEntry
For Each Entry In Zip
Try
Entry.ExtractWithPassword(BaseCompDestination, ExtractExistingFileAction.OverwriteSilently, Password)
setTaskText(Entry.FileName)
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
Next
End Using
I still tying to understand the reason why this happen, but I've found a solution,
After updater.exe done update process, I need to set all files and folders in ProgramData\MyAppSettings to NORMAL attribute at the MyApplication.exe first launch (first launch after update)
File.SetAttributes(sFile.FullName, FileAttributes.Normal)
MyDirectory.Attributes = FileAttributes.Directory
then I can hide them back (if only I want)
File.SetAttributes(sFile.FullName, File.GetAttributes(sFile.FullName) Or FileAttributes.Hidden Or FileAttributes.System)
MyDirectory.Attributes = FileAttributes.Directory Or FileAttributes.Hidden Or FileAttributes.System
Now the exception doesn't shows up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With