我正在尝试创建一个包含长参数字符串(> MAX_PATH)的快捷方式(在桌面上)。
MSDN documentation清楚地指出,对于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 (或更高版本)。
发布于 2011-02-12 04:19:19
事实证明,这个问题实际上只是Explorer shell对话框中的一个限制。生成的快捷方式文件没有260个字符的限制。原因很简单,对话框拒绝显示包含更多字符的Target。假设它使用固定长度的缓冲区调用GetPath
。
procedure TForm11.Button1Click(Sender: TObject);
var
sl: IShellLinkW;
pf: IPersistFile;
begin
CoCreateInstance(CLSID_ShellLink, nil,
CLSCTX_INPROC_SERVER, IID_IShellLinkW, sl);
sl.SetPath('c:\desktop\test.bat');
sl.SetWorkingDirectory('c:\desktop\');
sl.SetArguments(PChar(StringOfChar('x', 300)+'_the_end'));
pf := sl as IPersistFile;
pf.Save('c:\desktop\test.lnk', False);
end;
我的test.bat
看起来像这样:
echo %1> test.out
生成的test.out
直接指向_the_end!
https://stackoverflow.com/questions/4970075
复制相似问题