简体   繁体   English

在 Windows Vista/7 上通过 Inno Setup 将文件安装到原始用户的 My Docs 文件夹

[英]Install files to original user's My Docs folder via Inno Setup on Windows Vista/7

In the [Run] section of an Inno Setup script, there's a flag runasoriginaluser that allows the script to run a process as the original user:在 Inno Setup 脚本的[Run]部分,有一个标志runasoriginaluser允许脚本以原始用户身份运行进程:

the spawned process will execute with the (normally non-elevated) credentials of the user that started Setup initially (ie, the "pre-UAC dialog" credentials).生成的进程将使用最初启动安装程序的用户的(通常是非提升的)凭据(即“前 UAC 对话”凭据)执行。

Is there an equivalent flag or workaround for the {userdocs} shell folder constant? {userdocs} shell 文件夹常量是否有等效的标志或解决方法?

This is apparently a known limitation within Inno Setup (and other installers, generally), but I'm hoping someone knows a workaround.这显然是 Inno Setup(以及其他安装程序)中的一个已知限制,但我希望有人知道解决方法。

Excerpt from the Inno Setup help file:摘自 Inno Setup 帮助文件:

The "user" constants refer to the profile of the user running Setup. “用户”常量是指运行安装程序的用户的配置文件。 This user is often not the same as the currently logged-in user, so use the "user" constants with caution.此用户通常与当前登录的用户不同,因此请谨慎使用“用户”常量。

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, by setting PrivilegesRequired to lowest :如果安装程序仅为当前(非特权)用户安装应用程序,则不需要管理员权限,将PrivilegesRequired设置为lowest

     [Setup] PrivilegesRequired=lowest

    Then the "user" constants 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).在这种情况下,推荐的方法是使用{commonappdata}常量(或类似的)将文件安装到“Common”文件夹。 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 .请参阅仅在需要时使 Inno Setup 安装程序请求权限提升

For another similar questions, see对于另一个类似的问题,请参阅


Having that said, you can, as you have found yourself, by execute an external copy utility ( copy , xcopy , robocopy ) using the ExecAsOriginalUser function (or the runasoriginaluser flag in the [Run] section).话虽如此,您已经发现自己可以通过使用ExecAsOriginalUser函数(或[Run]部分中的runasoriginaluser标志)执行外部复制实用程序( copyxcopyrobocopy )。

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) .有关此方法的更多详细信息,请参阅类似问题Inno Setup Creating registry key for login user (not admin user)

Though, if the installer was started elevated straight away (as opposite to elevating itself), the above won't work.但是,如果安装程序立即开始提升(与提升自身相反),则上述方法将不起作用。 And it cannot work in this scenario anyway.无论如何它在这种情况下无法工作。 See How to write to the user's My Documents directory with installer when the user used 'Run As Administrator' .请参阅当用户使用“以管理员身份运行”时如何使用安装程序写入用户的“我的文档”目录 For this reason, stick with the approaches described above.因此,请坚持使用上述方法。

The workaround I came up with was using an external script to perform the data copy and calling the script using the ExecAsOriginalUser function in the wpReady page of the NextButtonClick event function.我想出了解决方法是使用一个外部脚本来执行数据复制,并呼吁使用脚本ExecAsOriginalUser功能在wpReady的页面NextButtonClick事件函数。

I'll provide more details if anyone is interested.如果有人感兴趣,我会提供更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM