Windows 快捷方式是否支持很长的参数长度?
我正在尝试创建一个包含长参数字符串(> MAX_PATH)的快捷方式(在桌面上)。
MSDN 文档明确指出Unicode 字符串 该字符串可以比 MAX_PATH 长。
生成的快捷方式恰好在 MAX_PATH 个字符之后被剪切(即 Path
+ Arguments
)。
我的实现是否有问题或者这是 Windows 的一些限制?
procedure CreateShortcut(APath: WideString;
AWorkingDirectory: WideString; AArguments: WideString; ADescription: WideString;
ALinkFileName: WideString);
var
IObject : IUnknown;
ISLink : IShellLinkW;
IPFile : IPersistFile;
begin
IObject := CreateComObject(CLSID_ShellLink);
ISLink := IObject as IShellLinkW;
ISLink.SetPath( PWideChar(APath));
ISLink.SetWorkingDirectory(PWideChar(AWorkingDirectory));
ISLink.SetArguments( PWideChar(AArguments));
ISLink.SetDescription( PWideChar(ADescription));
IPFile := IObject as IPersistFile;
IPFile.Save(PWideChar(ALinkFileName), False);
end;
PS:操作系统为Windows XP(及以上)。
I am trying to create a shortcut (on the Desktop) that contains a long argument string (> MAX_PATH).
The MSDN documentation clearly states that for Unicode string the string can be longer than MAX_PATH.
The resulting shortcut is cut exactly after MAX_PATH characters (that is the Path
+ the Arguments
).
Is there something wrong with my implementation or is this some Windows limitation?
procedure CreateShortcut(APath: WideString;
AWorkingDirectory: WideString; AArguments: WideString; ADescription: WideString;
ALinkFileName: WideString);
var
IObject : IUnknown;
ISLink : IShellLinkW;
IPFile : IPersistFile;
begin
IObject := CreateComObject(CLSID_ShellLink);
ISLink := IObject as IShellLinkW;
ISLink.SetPath( PWideChar(APath));
ISLink.SetWorkingDirectory(PWideChar(AWorkingDirectory));
ISLink.SetArguments( PWideChar(AArguments));
ISLink.SetDescription( PWideChar(ADescription));
IPFile := IObject as IPersistFile;
IPFile.Save(PWideChar(ALinkFileName), False);
end;
PS: OS is Windows XP (and above).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,这个问题实际上只是 Explorer shell 对话框中的限制。生成的快捷方式文件没有 260 个字符的限制。这只是对话框拒绝显示具有更多字符的目标。据推测,它使用固定长度的缓冲区调用
GetPath
。我的
test.bat
看起来像这样:生成的
test.out
直接到达_the_end!It turns out that this issue is in fact solely a limitation in the Explorer shell dialog. The generated shortcut file does not have a 260 character limitation. It's simply that the dialog refuse to display a Target with more characters than that. Presumably it calls
GetPath
with a fixed length buffer.My
test.bat
looks like this:The resulting
test.out
goes right the way to _the_end!感谢所有为该主题做出贡献的人 - 它对我帮助很大。
但是,如果可以的话,我想添加我在制定解决方案时发现的以下信息:
在 Windows 7 Enterprise ~SP1 上,似乎使用 VBS 创建快捷方式(至少)参数字段中的最大字符数仍然有限制。在被截断之前我测试了多达 1023 个字符。我认为同样的限制同样适用于 Delphi 方法。
在 Windows XP Professional ~SP3 上,虽然 VBS 方法将创建一个长度超过 260 个字符的快捷方式(lnk 文件包含数据),但在执行时似乎会在大约这个数字处截断它。
Thanks all who contributed to this thread - it helped me immensely.
However, if I may, I would like to add the below information I discovered in crafting my solution:
On Windows 7 Enterprise ~SP1, it would seem that using VBS to create the shortcut there is still a limit on maximum characters in (at least) the arguments field. I tested up to 1023 chars before it got trunicated. I presume the same limit would apply to the Delphi method likewise.
On Windows XP Professional ~SP3, while the VBS method will create a shortcut longer than 260 characters (lnk file contains the data), it seems to trunicate it at about this number when executing it.