Inno Setup - 在Windows 10中的公共用户文档中创建文件夹

问题描述 投票:1回答:1

我正在尝试将文件夹添加到最终将保存用户输出数据的安装中。我无法将文件夹放入Program Files,因为用户没有必要的权限来写入它。

如果它没有安装到Program Files,那么可以在应用程序文件夹中创建数据文件夹(这很好)。

我有一小段代码来检测安装是否是对Program Files进行的,如果是的话,我想使用CreateDir()C:\Users\Public\Documents\{'MyAppName}\DB中创建一个数据文件夹这似乎失败了,即使标准的Inno Setup脚本工作,它仍然在[Code]中:

[Dirs]
Name: "{commondocs}\{#MyAppName}\DB"

一旦路径确定,我正在使用DeinitialiseSetup()程序在安装结束时实现这一点。

这是我的代码:

[Code]
  procedure DeinitializeSetup();
  begin
    { If it has been installed in the Program Files Folder put DB in Public Documents }
    if Pos(ExpandConstant('{pf}'),ExpandConstant('{app}')) > 0 then                       
    begin
      if not CreateDir (ExpandConstant('{commondocs}\{#MyAppName}\DB')) then
        MsgBox('Error: Data folder could not be created.', mbInformation, MB_OK);
    end
      else
    begin
      if not CreateDir (ExpandConstant('{app}\DB')) then
        MsgBox('Error: Data folder could not be created.', mbCriticalError, MB_OK);
     end;
  end;

根据我的另一个建议,我使用了:

PrivilegesRequired=lowest

在脚本中但它无论是否有效都没有。我开始认为这可能是一个权限问题,但我不知道为什么,因为安装程序标准[Dirs]脚本工作正常。

这与关于识别路径的其他问题不同 - 我已经获得了我想要的所有路径:[Code] CreateDir()似乎无法在{commondocs}中创建文件夹。

非常感谢任何建议。

windows installation installer inno-setup pascalscript
1个回答
1
投票

我的猜测是{commondocs}\{#MyAppName}不存在。 CreateDir function只能创建一个目录。如果它们不存在,它将不会为您创建父文件夹(与[Dirs]部分条目相反)。

您可以使用ForceDirectories function代替:

一次创建指定目录路径中的所有目录。


附注:不要使用DeinitializeSetup创建目录 - 即使安装失败,或者即使用户取消安装,也会触发。

使用CurStepChanged(ssPostInstall)

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    { Your code }
  end;
end;
© www.soinside.com 2019 - 2024. All rights reserved.