Installer access to %appdata%

Mark Siegesmund 1 Reputation point
2022-03-30T19:08:02.343+00:00

When a installer runs as administrator then the %APPDATA% resolves to the administrator not the user we want to install to. How do I access the logged in users appdata directory?

Community Center | Not monitored
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Michael Taylor 61,101 Reputation points
    2022-03-30T20:37:42.207+00:00

    If I understand your problem correctly then I think you're mixing concerns. It sounds like you have an install that requires admin privileges. Therefore to install the application an administrator runs it for the user. This is assuming the user isn't an admin and UAC is enabled. In this situation the "logged in user" is the administrator. They are running the process in an isolated login session and none of the other login sessions are relevant. Thus the administrator's AppData directory is the logged in user's AppData.

    In the other scenario where the user is an admin and they get elevated via UAC when running the installer then the user (and their elevated user account) are the same and therefore the AppData directories are the same. There should be no issues here.

    Now comes the question of why your app needs access to the AppData directory. There are a couple of situations that come to mind. But one very important thing to consider here is that the user who is "logged in" when the app is installed may not be the same user that runs the app. Of course your installer could be per-user but in that case you wouldn't need an "admin" account to install it so I'm ignoring that situation.

    • Your installer needs to drop some "starter" files such that when a user runs your app they can access the files. In this case it makes the most sense to put the starter files either in the application's directory itself or perhaps in the common appdata directory. This gives all users access to the file(s) and at app startup you would want to detect that the currently running user doesn't have a copy of these file(s) in their own appdata and therefore should be copied over. I would argue this is the most common case.
    • Your installer needs some data files that are shared by all users. In that case the data needs to reside in a shared location and the common appdata directory makes most sense.
    • You want to write data while your app runs. In this case it isn't an installer issue but something your app would do at runtime. At runtime you would have write access to the currently running user's appdata directory and can store files there directly.
    0 comments No comments

  2. Mark Siegesmund 1 Reputation point
    2022-03-30T21:37:42.343+00:00

    The problem case is the end user is logged in as a normal non-admin, then runs the installer and is prompted for the administrator password. After entering it the installer copies most of the files to program files and then sets up some user preferences files in APPDATA. Once the installer is done and the application is run we expect those user preferences to be available to the program in user mode. We don't need to share data between users. When the user is the admin then all works. We have the same problem with the desktop icon.

    We thought we had a solution where we looked at logged in users and figured out the right appdata path from there. This however fails when a user changes his name becauase the appdata path does not use the new name. I can't find a way to find the apdata path for a given user.


  3. Mark Siegesmund 1 Reputation point
    2022-03-31T15:33:37.673+00:00

    That is the action I want. How does MSI figure out where to install it to? That is, what appdata directory?

    I use inno for an installer since we still need to support XP.


  4. RLWA32 51,366 Reputation points
    2022-03-31T18:20:19.403+00:00

    I suggest you pursue your questions about inno setup at the software author's forums here - https://jrsoftware.org/forums.php

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.