Reputation: 1341
I have an application that requires a SQLite DB in order to run. In my NSIS script, the DB is copied to the users Local/AppData folder. This works fine, if the user who install the program is an admin user.
However, if a standard user tries to install the program, the installer asks for admin password (since standard users can't install programs on windows) and the user installing, is now being switched to an admin, causing the DB to be installed in the admins Local/AppData folder instead of the actual users AppData folder.
So, in effect, when the standard user tries to run the program, it can't find the DB.
I'm not sure how to handle this situation (best practice if any) and can't find a question answering it.
Should the installer drop the DB into a public place, like AllUsers and on first run copy the DB from there into their own AppData folder?
Problem with allusers folder seem to me being that anyone can peek into it and possibly delete files.
Upvotes: 2
Views: 1858
Reputation: 101764
Standard users can install applications. Install the program under $LocalAppdata\Programs\MyApp (FOLDERID_UserProgramFiles) and write the uninstall information under HKCU
. NSIS has the special SHCTX
registry root (controlled by SetShellVarContext
) that helps with this if you want to support both types of install modes in one installer.
If you want to force the user to always elevate to administrator then the recommended approach is indeed to store a template/basic version of your database in the AllUsers appdata (known as ProgramData in Vista+) (SetShellVarContext all
+ $AppData
) or Common ProgramFiles ($COMMONFILES
) folder and have your application make a copy on first run for a particular user. Only administrators can delete files in these locations. Most users will have read access but that should not matter because the files should not contain user specific information.
You can find these recommendations in Certification requirements for Windows desktop apps or the older Windows Logo requirements documentation:
10.3 Your app data, which must be shared among users on the computer, should be stored within ProgramData
10.4 Your app’s data that is exclusive to a specific user and that is not to be shared with other users of the computer, must be stored in Users\\AppData
10.6 Your app must write user data at first run and not during the installation in “per-machine” installations
When the app is installed, there is no correct user location in which to store data. Attempts by an app to modify default association behaviors at a machine level after installation will be unsuccessful. Instead, defaults must be claimed on a per-user level, which prevents multiple users from overwriting each other's defaults.
Upvotes: 5