How to follow a .lnk file programmatically

前端 未结 5 725
故里飘歌
故里飘歌 2020-12-10 04:24

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.

What practical

5条回答
  •  温柔的废话
    2020-12-10 05:02

    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);
    

    The shortcut object "sc" has a TargetPath property.

提交回复
热议问题