DavidSlade
Posts: 14
Joined: Tue Jun 05, 2018 7:04 am

Local application data

I am installing an app that puts a database in Local Application Data. When the installer is run on a non admin account it requests elevation to start the install. This is ok, but the installer then puts the database in the admin's Appdata folder, where it is inaccessible. I want it in the user's Appdata folder. How do I do that?
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Local application data

Hello,

This happens indeed when you are using a per-machine installation. All user location will be resolved to the user paths specific to the user account you filled in on UAC elevation prompt.

To achieve what you need you can add your database file as a temporary file in "Files and Folders" page and then at the end of the installation use a custom action which will copy the temp database file into the current user account local appdata folder.

You should just add your custom action as a custom action with sequence scheduled after "Install Execution Stage -> Finish Execution" action group. This way your custom action will be launched under the user account context which launched the setup and not under the admin user account context under which the setup was installed (filled in on UAC prompt).

Hope this helped.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
DavidSlade
Posts: 14
Joined: Tue Jun 05, 2018 7:04 am

Re: Local application data

Thanks Daniel,
Although if I am performing a per-machine installation I guess I should be putting the data in ProgramData?
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Local application data

You are always welcome.

Yes, I think this would be a best practice.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Tvalone
Posts: 42
Joined: Sat Jul 02, 2016 1:40 am

Re: Local application data

Daniel do you have a sample of a custom action copying a file from the programs file folder to the appdata folder?
Catalin
Posts: 6600
Joined: Wed Jun 13, 2018 7:49 am

Re: Local application data

Hello Toren,

Here is a little PowerShell script that copies a file from ProgramFiles to AppData folder. For this, I have used the "$env:APPDATA" environment variable which resolves to the following path:

Code: Select all

C:\Users\<user>\AppData\Roaming
The script is as it follows:

Code: Select all

Copy-Item -Path "the\path\to\your file" -Destination $env:APPDATA
This can be added in your Advanced Installer project by going to "Custom Actions" page and adding a "Run PowerShell inline script" custom action with sequence. In order to add a custom action with sequence, all you have to do is to press the "Add custom action with sequence" button which is placed to the right side of the custom action's name.

Since you probably want to copy a file that you have earlier installed, you should schedule this custom action after the "Add Resources" action group and with its execution time of "When the system is being modified (deferred)".

I have attached a screenshot to this thread for your reference.
PowerShell CA.PNG
PowerShell CA.PNG (56.21 KiB) Viewed 4319 times
All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”