4

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 does not have a constant for this folder)

My goal is to have the install create a C:\Users\Public\MyApp folder with some files in it. However when I run the install, it is creating the folder here: C:\Users\Public\Public Documents\MyApp

Is this a permissions issue where the installer doesn't have access to create a folder directly under C:\Users\Public?

[Files]
Source: "MyApp\db.mdf"; DestDir: "{drive:{src}}\Users\Public\MyApp"; Flags: ignoreversion;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
jrhoads23
  • 109
  • 1
  • 8
  • I cannot reproduce this. Try suggestions in my answer. And if it does not help, show us a log file. + What version of Windows are you testing this on? – Martin Prikryl Apr 12 '17 at 06:46

1 Answers1

5

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}).

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • You sir, are a genius. I however am not. I made a very simple Inno Setup file to test and you are correct... it maps correctly to C:\Users\Public. Looking at my original Inno file, I found my mistake. I had a Check parameter which would run one command for XP and another for more recent O/S. Well I had that Check command switched between the two so it was calling my XP code on my Windows 10 system (trying to put it at C:\Documents and Settings\All Users\Documents ) – jrhoads23 Apr 12 '17 at 13:26
  • As for your comment "One usually does not want the C:\Users\Public"... why is the reasoning behind that? Are you saying I should be putting my mdb under the C:\Users\Public\Public Documents folder? – jrhoads23 Apr 12 '17 at 13:29
  • Shared user-visible documents should go to `C:\Users\Public\Public Documents`. Shared private application data should go to `C:\ProgramData` - I've understood that you have to deploy your files to `C:\Users\Public`, because you have no control over the location. – Martin Prikryl Apr 12 '17 at 13:49