【问题标题】:Create shortcut to directory via IShellLink通过 IShellLink 创建目录的快捷方式
【发布时间】:2013-03-31 18:33:57
【问题描述】:

问题:我需要在 C# 中使用自定义图标创建目录的快捷方式(没有 .NET API)

到目前为止,我已经完成了:在我的 C# 代码中,我正在查询 IShellLink 对象(实际上是 IShellLinkA),通过 SetPath 将其目标路径设置为 @"S:\my\myDirectory\"(我也尝试不使用最后一个斜杠),通过 SetIconLocation 将图标设置为 @ 987654323@,而不是调用Save(@"S:\foo.lnk", true); 如果这很重要,S: 是具有写访问权限的网络驱动器

我在资源管理器下获得带有正确图标的快捷方式,但双击后我收到波兰语错误消息“Windows 正在搜索文件 myDirectory,如果您知道该位置使用浏览功能”。当我右键单击快捷方式并选择属性时,我得到"Target type: file"。当我在资源管理器下手动创建目录的快捷方式时,有"Target type: directory"

我肯定遗漏了一些明显的东西,但我花了过去 30 分钟在 Google 和 MSDN 上搜索“快捷方式/IShellLink to directory”,但没有发现任何用处

编辑:按要求发布来源:

我正在使用来自this 站点的 IShellLink 实现,我的代码非常简单:

ShellShortcut shortcut = new ShellShortcut(@"S:\foo.lnk");
shortcut.Description = "Sample item";
shortcut.IconPath = @"S:\my\myDirectory\icon.ico";
shortcut.IconIndex = Convert.ToInt32(0);
shortcut.Path = @"S:\my\myDirectory\";
shortcut.WorkingDirectory = @"S:\my\myDirectory\";
shortcut.Save();

【问题讨论】:

  • 你描述的听起来不错,你能发布实际代码吗?

标签: shortcut windows-shell


【解决方案1】:

看来我需要新的眼光:/ 路径名中有一个很难看到的错字(l 而不是 i)...

【讨论】:

    猜你喜欢
    • 2015-10-06
    • 1970-01-01
    • 1970-01-01
    • 2021-10-04
    • 1970-01-01
    • 2010-09-19
    • 1970-01-01
    • 1970-01-01
    • 2020-03-07
    相关资源
    最近更新 更多