避免“无法扩展shell文件夹常量userdocs". Inno Setup中的错误 [英] Avoiding "Failed to expand shell folder constant userdocs" errors in Inno Setup
问题描述
我将一些示例文档安装到Windows上标准我的文档"文件夹的"PerfectTablePlan"子文件夹中.这对于99%+的用户来说效果很好.但是,如果用户没有我的文档"文件夹,则会收到许多丑陋的错误消息,形式如下:
I install some sample documents into a 'PerfectTablePlan' sub-folder of the standard 'My documents' folder on Windows. This works fine for 99%+ of users. But if a user doesn't have a 'My documents' folder I get a number of ugly error messages of the form:
内部错误:无法扩展shell文件夹常量"userdocs"
Internal error:Failed to expand shell folder constant "userdocs"
这不是给用户鼓舞的信心!
This is not very confidence inspiring for the user!
不为这些用户安装样本(或将它们安装在其他地方)也是可以接受的.但不要显示丑陋的错误消息.
It is acceptable to not install the samples for these users (or install them somewhere else). But not to show the ugly error messages.
问题似乎来自{userdocs}的ExpandConstant宏扩展.
The problem seems to come from the ExpandConstant macro expansion of {userdocs}.
是否有某种方法可以在不使用宏的情况下获取我的文档"的路径?
Is there some way I can get the path of 'My documents' without using a macro?
还是某种抑制错误消息的方法? ExpandConstant引发异常: http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_expandconstant
Or some way to suppress the error message? ExpandConstant throws an exception: http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_expandconstant
.iss文件的相关部分如下所示:
The relevant parts of my .iss file looks like this:
#define MySampleDir "{code:SampleDirRoot}\PerfectTablePlan"
...
[Files]
Source: ..\binaries\windows\program\plans\*_v14.tp; DestDir: {#MySampleDir}\; Flags: ignoreversion onlyifdoesntexist createallsubdirs recursesubdirs uninsneveruninstall;
Source: ..\binaries\windows\program\plans\*_v3.tps; DestDir: {#MySampleDir}\; Flags: ignoreversion onlyifdoesntexist createallsubdirs recursesubdirs uninsneveruninstall;
...
[Code]
function SampleDirRoot(Param: String): String;
begin
if DirExists( ExpandConstant('{userdocs}') ) then
Result := ExpandConstant('{userdocs}')
else
Result := ExpandConstant('{allusersprofile}')
end;
推荐答案
例外:
无法扩展shell文件夹常量常量名称"
Failed to expand shell folder constant 'constant name'
当内部调用 CSIDL_PERSONAL
标识符.
is raised when the internally called SHGetFolderPath
function (called from inside ExpandConstant
when expanding a shell folder constant) returns an empty path string for the given folder CSIDL, in this case for the CSIDL_PERSONAL
identifier.
That means the user doesn't have the CSIDL_PERSONAL
folder. It makes me wonder how can one configure Windows' user account to not have that folder. Well, you can workaround this issue (or Windows misconfiguration ?) by catching the raised internal exception in the try..except
block:
[Code]
function SampleDirRoot(Param: string): string;
var
Folder: string;
begin
try
// first try to expand the {userdocs} folder; if this raises that
// internal exception, you'll fall down to the except block where
// you expand the {allusersprofile}
Folder := ExpandConstant('{userdocs}');
// the {userdocs} folder expanding succeded, so let's test if the
// folder exists and if not, expand {allusersprofile}
if not DirExists(Folder) then
Folder := ExpandConstant('{allusersprofile}');
except
Folder := ExpandConstant('{allusersprofile}');
end;
// return the result
Result := Folder;
end;
But I've never heard about possibility of not having the CSIDL_PERSONAL
folder. Please note, that the above code protects only the {userdocs}
constant.
这篇关于避免“无法扩展shell文件夹常量userdocs". Inno Setup中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!