如何以编程方式跟踪.lnk文件

use*_*412 12 .net c# windows winapi winforms

我们有一个充满快捷方式(.lnk文件)的网络驱动器,指向文件夹,我需要在C#Winforms应用程序中以编程方式遍历它们.

我有什么实际选择?

djd*_*lib 13

添加IWshRuntimeLibrary作为项目的参考.添加引用,COM选项卡,Windows脚本主机对象模型.

以下是我获取快捷方式属性的方法:

IWshRuntimeLibrary.IWshShell wsh = new IWshRuntimeLibrary.WshShellClass();
IWshRuntimeLibrary.IWshShortcut sc = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(filename);
Run Code Online (Sandbox Code Playgroud)

快捷方式对象"sc"具有TargetPath属性.

  • 感谢您的**简单实用的**建议和示例,并没有给我更多信息来挖掘.我建议添加到您的答案的一件事是您添加对COM对象"Windows脚本宿主对象模型"的引用以获取IWshRuntimeLibrary. (6认同)
  • 我要补充一点,如果你得到'_Interop类型'IWshRuntimeLibrary.WshShellClass'就无法嵌入.使用适用的界面而不是编译错误.在参考文献中选择IWshRuntimeLibrary并将'嵌入互操作类型'属性从True设置为False. (4认同)