Inno Setup - puts user files in admin documents

后端 未结 1 1136
温柔的废话
温柔的废话 2020-12-20 08:42

I have a few Windows 7 users who, when installing and logged in as themselves, are asked to provide the Admin password. When this happens, Inno Setup installs the program fo

相关标签:
1条回答
  • 2020-12-20 09:18

    Your approach is not correct.

    There two correct ways:

    1. If the installer installs the application for the current (unprivileged) user only, do not require Administrator privileges.

      PrivilegesRequired=lowest
      

      Then the {userappdata} constant (and similar) will correctly refer to the current user's folder.

    2. If the installer installs the application for all users, it does not make sense to put some files to folder of one specific users. All users need the files, not just the one. In this case the recommended approach is to install the files to "Common" folder, using the {commonappdata} constant (or similar). And have the application copy the files to the user folder on the first run.

      See also How to write to the user's My Documents directory with installer when the user used 'Run As Administrator'.

    You can also allow the user choose between these two approaches.
    See Make Inno Setup installer request privileges elevation only when needed.

    For another similar questions, see

    • Inno Setup Using {localappdata} for logged in user
    • Inno Setup always installs into admin's AppData directory

    Having that said, you can do, what you ask for, by executing an external copy utility (copy, xcopy, robocopy) using the ExecAsOriginalUser function (or the runasoriginaluser flag in the [Run] section).

    ExecAsOriginalUser(
      'cmd.exe', '/c xcopy.exe "sourcefile" "%APPDATA%"',
      '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
    

    For more detail on this approach, see a similar question Inno Setup Creating registry key for logged in user (not admin user).

    0 讨论(0)
提交回复
热议问题