简体   繁体   English

Inno Setup - 从需要特权的安装程序访问非特权帐户文件夹

[英]Inno Setup - Access unprivileged account folders from installer that requires privileges

I'm using Inno Setup to install documents/files rather than an application, and this is primarily for Windows 7 users.我使用 Inno Setup 来安装文档/文件而不是应用程序,这主要适用于 Windows 7 用户。 As such my DestDir is based on {userdocs} so that all files will be installed in a folder below that user's Documents library.因此,我的DestDir基于{userdocs}因此所有文件都将安装在该用户的 Documents 库下的文件夹中。

The problem arises when I use the same installer to install a TTF font.当我使用相同的安装程序安装 TTF 字体时,就会出现问题。 This requires elevated privileges ( admin or superuser ).这需要提升的权限( adminsuperuser )。 The problem I'm seeing is that if a non-admin user runs the install, they are correctly prompted via UAC for the admin/superuser password...but at that point the DestDir for the installation changes to the Admin documents folder rather than the user's documents folder.我看到的问题是,如果非管理员用户运行安装,他们会通过 UAC 正确提示输入管理员/超级用户密码......但此时安装的DestDir更改为 Admin 文档文件夹而不是用户的文档文件夹。 Is there any way to work around this or prevent this from happening?有没有办法解决这个问题或防止这种情况发生?

Example, non-Admin account Fre has a documents path of:例如,非管理员帐户Fre的文档路径为:

C:\Users\Fred\My Documents\

And if I do not include the TTF font as part of the installation, this is what the installer will use as the base path for the installation {userdocs} and it works perfectly.如果我不将 TTF 字体作为安装的一部分,这就是安装程序将用作安装{userdocs}的基本路径的内容,并且它可以完美运行。

If I DO include the TTF font as part of the installation with same non-Admin user Fred, by the time the install is done {userdocs} has become如果我确实将 TTF 字体作为安装的一部分包含在同一非管理员用户 Fred 的安装中,则在安装完成时{userdocs}已成为

C:\Users\AdminUser\My Documents\ 

...which is not the intended result...just need Admin privileges for the font installation piece and need the files installed into the actual user's documents area. ...这不是预期的结果...只需要字体安装部分的管理员权限,并且需要将文件安装到实际用户的文档区域中。

Thanks.谢谢。

Create a child installer for the fonts, with the PrivilegesRequired=admin directive , that you will run from within the master non-elevated installer.使用PrivilegesRequired=admin指令为字体创建子安装程序,您将从主非提升安装程序中运行该子安装程序。

Master installer code will be like:主安装程序代码将如下所示:

[Setup]
PrivilegesRequired=lowest

[Files]
Source: "ttfsetup.exe"; DestDir: {tmp}; Flags: deleteafterinstall

[Run]
Filename: "{tmp}\ttfsetup.exe"; Parameters: /silent; StatusMsg: "Installing TTF fonts..."

And of course, you should uninstall the child installer from the master uninstaller.当然,您应该从主卸载程序卸载子安装程序。

You may also want to make sure, the user did not run the master installer with administrator privileges explicitly.您可能还想确保用户没有明确以管理员权限运行主安装程序。 See my answer to How to write to the user's My Documents directory with installer when the user used 'Run As Administrator' .请参阅我对如何在用户使用“以管理员身份运行”时使用安装程序写入用户的我的文档目录的回答。

Another way to implement this is to useShellExec function with runas verb to execute an elevated external copy utility ( copy , xcopy , robocopy ).另一种实现方法是使用带有runas动词的ShellExec函数来执行提升的外部复制实用程序( copyxcopyrobocopy )。 See Inno Setup - Register components as an administrator (it runs regsvr32 , but the concept is the same).请参阅Inno Setup - 以管理员身份注册组件(它运行regsvr32 ,但概念是相同的)。


Another option is to execute a non-elevated process, from the elevated installer, only to resolve the path to the original user documents folder.另一种选择是从提升的安装程序执行非提升的过程,仅解析原始用户文档文件夹的路径。

Use the ExecAsOriginalUser function .使用ExecAsOriginalUser函数

You have to exchange the path between the installers via some temporary file that is accessible to both accounts.您必须通过两个帐户都可以访问的一些临时文件来交换安装程序之间的路径。 Eg a file in {commondocs} , as can be seen in the Inno Setup always installs into admin's AppData directory .例如,在{commondocs}的文件,可以在Inno Setup 中看到总是安装到管理员的 AppData 目录中

[Files]
Source: "*.txt"; DestDir: "{code:GetUserDocumentsFolder}"

[Code]

var
  UserDocumentsFolder: string;

function GetUserDocumentsFolder(Params: string): string;
begin
  Result := UserDocumentsFolder;
end;

function InitializeSetup(): Boolean;
var
  TempFile: string;
  Code: string;
  Buf: TArrayOfString;
  ResultCode: Integer;
begin
  Result := True;

  TempFile := { some path accessible by both users };
  Code :=
    '[Environment]::GetFolderPath(''MyDocuments'') | ' +
    'Out-File "' + TempFile + '" -Encoding UTF8';
  Log(Format('Executing: %s', [Code]));
  if (not ExecAsOriginalUser('powershell.exe', Code, '', SW_HIDE,
                             ewWaitUntilTerminated, ResultCode)) or
     (ResultCode <> 0) or
     (not LoadStringsFromFile(TempFile, Buf)) then
  begin
    MsgBox('Failed to resolve user MyDocuments path', mbError, MB_OK);
    Result := False;
  end
    else
  begin
    UserDocumentsFolder := Buf[0];
    Log(Format('User Documents path resolved to "%s"', [UserDocumentsFolder]));
  end;
end;

Related discussions:相关讨论:

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

相关问题 Inno安装程序安装程序在Windows 7中不起作用 - Inno Setup Installer Not Working in Windows 7 Inno Setup 生产的安装程序需要提升。 我该如何避免? - Installer produced by Inno Setup requires elevation. How do I avoid that? 在Inno Setup安装中运行另一个安装程序 - Run another installer in an Inno Setup installation 为MSI文件构建Inno Setup安装程序 - Building Inno Setup installer for MSI files Microsoft SmartScreen - 使用 Inno Setup 安装程序暂停? - Microsoft SmartScreen - suspended using Inno Setup installer? Inno Setup:如何在安装程序中集成管理员凭据 - Inno Setup : how to integrate admin credentials in the installer 如何从注册表中获取Office的安装目录以安装Inno Setup安装程序 - How to take the Office's install directory from registry for an Inno Setup installer 从以管理员身份运行的 Inno Setup 安装程序为当前登录的用户安装应用程序 - Installing application for currently logged in user from Inno Setup installer running as Administrator Inno Setup Batch 并行编译多个安装程序 - Inno Setup Batch compile more than one installer in parallel 任何人都知道Inno Setup的可靠.NET Framework 2.0安装程序脚本吗? - Anyone know of a solid .NET Framework 2.0 installer script for Inno Setup?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM