Inno Setup不会在C:\ Users \ Public下创建文件夹-而是执行C:\ Users \ Public \ Public Documents [英] Inno Setup will not create folder under C:\Users\Public - will instead do C:\Users\Public\Public Documents
问题描述
我正在使用Inno Setup来构建我的安装程序,并且在[Files]
部分中硬编码了C:\Users\Public
文件夹以放置一些文件(Inno Setup在该文件夹中没有常量)
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)
我的目标是让安装创建一个C:\Users\Public\MyApp
文件夹,其中包含一些文件.但是,当我运行安装时,它将在这里创建文件夹:
C:\Users\Public\Public Documents\MyApp
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
这是权限问题,安装程序无权直接在C:\Users\Public
下创建文件夹吗?
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;
推荐答案
我无法重现您的问题.对我来说,您的代码有效.我已经在Windows Vista,7和10上对其进行了测试.它总是安装到C:\Users\Public\MyApp
.
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
.
尽管我不理解{drive:{src}}
. Users
文件夹的驱动器与安装程序的驱动器有什么关系?您应该使用 {sd}
常量:
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
但是无论如何,要解析C:\Users\Public
的路径,可以使用PUBLIC
环境变量:
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
从Windows Vista开始运行.
It works since Windows Vista.
或者,您可以使用 FOLDERID_Public
.有关示例代码,请参见对AppData \ LocalLow是否恒定?
Alternatively, you can use SHGetKnownFolderPath
with FOLDERID_Public
. For an example code, see Constant for AppData\LocalLow?
如果甚至需要支持没有C:\Users\Public
文件夹或PUBLIC
变量的Windows XP,则必须找出在其中使用的替代路径(可能是C:\Documents and Settings\All Users
),并实施使用脚本化常量进行后备:
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;
对于其他人,值得注意的是,您对解析C:\Users\Public
的需求非常具体,与以下问题有关: C ++应用程序MDB我不希望ProgramData中的文件复制到用户的AppData文件夹中.
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.
通常不希望C:\Users\Public
,而是C:\Users\Public\Documents
(= {commonappdata}
).
One usually does not want the C:\Users\Public
, but C:\Users\Public\Documents
(= {commondocs}
) or C:\ProgramData
aka C:\Users\All Users
(= {commonappdata}
).
这篇关于Inno Setup不会在C:\ Users \ Public下创建文件夹-而是执行C:\ Users \ Public \ Public Documents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!