Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows快捷方式是否支持很长的参数长度?_Windows_Delphi_Delphi 2007_Shortcut_Maxlength - Fatal编程技术网

Windows快捷方式是否支持很长的参数长度?

Windows快捷方式是否支持很长的参数长度?,windows,delphi,delphi-2007,shortcut,maxlength,Windows,Delphi,Delphi 2007,Shortcut,Maxlength,我正在尝试创建一个包含长参数字符串(>MAX\u PATH)的快捷方式(在桌面上) 声明中明确指出,对于Unicode字符串,字符串可以长于MAX_PATH 生成的快捷方式正好在MAX_PATH字符之后剪切(即路径+参数) 我的实现是否有问题,或者这是Windows的限制 procedure CreateShortcut(APath: WideString; AWorkingDirectory: WideString; AArguments: WideString; ADescription

我正在尝试创建一个包含长参数字符串(>MAX\u PATH)的快捷方式(在桌面上)

声明中明确指出,对于Unicode字符串,字符串可以长于MAX_PATH

生成的快捷方式正好在MAX_PATH字符之后剪切(即
路径
+
参数

我的实现是否有问题,或者这是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:OS是Windows XP(及以上版本)。

事实证明,这个问题实际上只是浏览器外壳对话框中的一个限制。生成的快捷方式文件没有260个字符的限制。很简单,对话框拒绝显示字符数超过该字符数的目标。大概它使用固定长度的缓冲区调用
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
直接到达了终点

感谢所有为这篇文章做出贡献的人——它给了我极大的帮助

但是,如果可以的话,我想添加我在制定解决方案时发现的以下信息:

1) 在Windows7Enterprise~SP1上,使用参数字段(至少)中的最大字符数似乎仍然有限制。我测试了多达1023个字符,然后才被认证。我认为同样的限制也适用于德尔菲法


2) 在Windows XP Professional~SP3上,虽然VBS方法将创建一个长度超过260个字符(lnk文件包含数据)的快捷方式,但在执行它时,它似乎将该快捷方式设置为大约这个数字。

是否尝试使用\\?\前缀启用长文件名?例如,\\?\D:\very\long\path-请参阅@David:Yes,这会导致资源管理器挂起几秒钟,限制仍然存在。是什么切断了参数、路径还是工作目录?我觉得您需要使用SetIDList而不是SetPath。@David:当您将path和参数(在资源管理器对话框中称为“target”)组合在一起时得到的字符串将被削减到260个字符。我认为这是shell对话框中的一个限制,而不是支持它的shell链接中的一些基本内容。执行快捷方式时会发生什么情况?它的行为是否正确?我可以确认W7上的D2007有311字节的“test.out”。@Andreas你太好了,但我根本不值得与Raymond相比!!