如何以编程方式遵循.lnk文件方式、文件、lnk

2023-09-02 21:36:34 作者:鹰击长空踏轻云

我们有一个网络驱动器完全快捷方式(.LNK文件)指向的文件夹,我需要编程遍历他们在C#的WinForms应用程序。

We have a network drive full of shortcuts (.lnk files) that point to folders and I need to traverse them programmatically in a C# Winforms app.

什么的实际的选择我呢?

推荐答案

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

Add IWshRuntimeLibrary as a reference to your project. Add Reference, COM tab, Windows Scripting Host Object Model.

下面是我如何得到一个快捷方式的属性:

Here is how I get the properties of a shortcut:

IWshRuntimeLibrary.IWshShell wsh = new IWshRuntimeLibrary.WshShellClass();
IWshRuntimeLibrary.IWshShortcut sc = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(filename);

快捷方式对象SC有TARGETPATH​​属性。

The shortcut object "sc" has a TargetPath property.