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.
- MyApplication.exe starts at windows start.
- User Login into the MyApplication.
- Show Updates Available window and the User clicks on the update now button.
- Prompt
UACand Launch updater.exe as Administrator. Then terminate the MyApplication.exe - The updater.exe will download zip files and extract them to correct folders.
- Then the updater will start MyApplication.exe again and terminate themself.
All 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

