Inno Setup will not create folder under C:\Users\Public - will instead do C:\Users\Public\Public Documents

后端 未结 1 1487
傲寒
傲寒 2020-12-19 14:50

I am using Inno Setup to build my installer and I have the C:\\Users\\Public folder hardcoded in my [Files] section to place some files (Inno Setup

相关标签:
1条回答
  • 2020-12-19 15:11

    I cannot reproduce your problem. For me your code works. I've tested it on Windows Vista, 7 and 10. It always installs to C:\Users\Public\MyApp.


    Though I do not understand the {drive:{src}}. How does the drive of the Users folder relate to the drive of the installer? You should use the {sd} constant:

    [Files]
    Source: "MyApp\db.mdf"; DestDir: "{sd}\Users\Public\MyApp"; Flags: ignoreversion
    

    But anyway, to resolve the path to the C:\Users\Public, you can use the PUBLIC environment variable:

    [Files]
    Source: "MyApp\db.mdf"; DestDir: "{%PUBLIC}\MyApp"; Flags: ignoreversion
    

    It works since Windows Vista.

    Alternatively, you can use SHGetKnownFolderPath with FOLDERID_Public. For an example code, see Constant for AppData\LocalLow?


    If you need to support even Windows XP, where there is no C:\Users\Public folder or PUBLIC variable, you have to find out, what path your need to use there instead (probably C:\Documents and Settings\All Users), and implement a fallback using a scripted constant:

    [Files]
    Source: "MyProg.exe"; DestDir: "{code:GetPublicPath}\MyApp"; Flags: ignoreversion
    
    [Code]
    
    function GetPublicPath(Param: string): string;
    begin
      Result := GetEnv('PUBLIC');
      if Result <> '' then
      begin
        Log(Format('PUBLIC is "%s"', [Result]));
      end
        else
      begin
        Result := GetEnv('ALLUSERSPROFILE');
        Log(Format('PUBLIC is not set, ALLUSERSPROFILE is "%s"', [Result]));
      end;
    end;
    

    And for others, it's worth noting that your need for resolve C:\Users\Public is very specific, related to this question: C++ app MDB in ProgramData copies to user's AppData folder when I dont want it to.

    One usually does not want the C:\Users\Public, but C:\Users\Public\Documents (= {commondocs}) or C:\ProgramData aka C:\Users\All Users (= {commonappdata}).

    0 讨论(0)
提交回复
热议问题