Inno Setup - 在 Public 中创建文件夹 在 Windows 中创建用户文档 10

Inno Setup - Create folder in Public Users Documents in Windows 10

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

如果未安装到 Program Files,则可以在应用程序文件夹中创建数据文件夹(这工作正常)。

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

[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;

按照我使用的另一个 SO 建议:

PrivilegesRequired=lowest

在脚本中,但不管有没有这个都不起作用。我开始认为这可能是一个权限问题,但我不确定为什么,因为安装程序标准 [Dirs] 脚本工作正常。

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

非常感谢您的任何建议。

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

您可以使用 ForceDirectories function 代替:

Creates all the directories along the specified directory path all at once.


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

使用CurStepChanged(ssPostInstall):

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    { Your code }
  end;
end;