如果特权不是Inno设置中的管理员,则在其他文件夹中安装文件



我想使用如下

之类的脚本
function InitializeSetup(): Boolean;
begin
  Result := not IsAdminLoggedOn;
  if Result then
  begin

检查用户是否是管理员。

但是,如果用户是管理员,我该怎么办,然后在C:program filesABC中安装A.txt,否则在D:TEST中?

我可以写点东西连接到 [Files]吗?

因为我也想在安装文件时使用检查路径,所以如果我可以组合[Code][Files],这对我来说可能更容易。

借口我缺乏知识,并提前感谢。

我试图使用它,

[Files]
Source: "..ABCCDE.txt"; DestDir: "{code:GetDirName}IJK"; 
    Check: DirExists(ExpandConstant('C:Program FilesFGH'))

,但是我不知道如何编写代码,如果我想在更多路径中安装更多文件。

这个不起作用:

function GetDirName(Param: string): string;
begin
  if IsAdminLoggedOn And DirExists(ExpandConstant('C:ABC')) then
  begin
    Result := ExpandConstant('C:ABCMy Program')
  end
    else
  begin
    if DirExists(ExpandConstant('C:DEF')) then
    begin
      Result := ExpandConstant('C:DEFMy Other Program');
    end
      else
    begin
      MsgBox('No destination found, aborting installation', mbError, MB_OK);
    end;
  end;
end;

只需实现 GetDirName脚本常数即可返回特权且毫无疑问的安装的其他路径。

[Files]
Source: "..ABCCDE.txt"; DestDir: "{code:GetDirName}"
[Code]
function GetDirName(Param: string): string;
begin
  if IsAdminLoggedOn then
    Result := ExpandConstant('{pf}My Program')
  else
    Result := ExpandConstant('{localappdata}My Program');
end;

如果要将不同的文件夹用于不同的文件,只需实现更多诸如GetDirName之类的功能。尽管区别仅与子文件夹有关,但您当然可以使用一个脚本常数函数来解析常见的根文件夹并在DestDir参数中附加子文件夹。


如果要更改整体安装目标,请在DefaultDirName指令中使用GetDirName脚本常数:

[Setup]
DefaultDirName={code:GetDirName}
[Files]
Source: "..ABCCDE.txt"; DestDir: "{app}"
[Code]
{ The same as above }

有关更复杂的示例,请参见"使Inno设置安装程序请求特权高程"。

最新更新